Basic SSH tutorial

In today’s connected world, the ability to access and manage computers remotely is essential for professionals and enthusiasts alike. Secure Shell, commonly known as SSH, is a reliable and secure method to remotely access another computer over a network. This detailed guide will take you through the process of using SSH for remote access, whether it’s connecting to a Linux machine from Windows or managing a remote server from your Mac.

Are you wondering how to remotely connect to another computer using SSH? Look no further. This article will provide all the information you need to successfully use SSH, configure your connection, and ensure a secure link to your remote workstation or server.

To learn more about SSH, visit the OpenSSH project.

What is SSH?

SSH, or Secure Shell, is a protocol that gives users a secure way to access a computer over an unsecured network. When you use SSH to connect to a remote computer, it encrypts your session, which safeguards your communications against potential intruders. Even if someone intercepts your data, they won’t be able to decipher it.

Installing SSH Clients and Servers

Before you can make an SSH connection, you need an SSH client on your local machine and an SSH server on the remote machine.

For Windows users, you can install an OpenSSH client or use alternatives like PuTTY. Mac and Linux users typically have SSH built into their systems.

Installing an SSH server on the remote machine varies based on the operating system. On Linux, you can install OpenSSH with your package manager. On Windows 10 or 11, OpenSSH Server can be enabled through the settings panel or PowerShell.

Making Your First SSH Connection

To start an SSH connection, you need the remote computer’s IP address or hostname and a username. Use the following command in your terminal or command prompt:

ssh username@hostname

For example, if your username is ‘john’ and the remote hostname is ‘example.com’, you would type:

ssh [email protected]

You’ll be prompted to accept the computer’s public key if connecting for the first time, followed by a request for your password.

Configuring SSH

Securing Your SSH Connection with Keys

Password authentication is the default method, but key-based authentication is more secure. To create an SSH key pair, use:

ssh-keygen

Then, transfer your public key to the remote server using:

ssh-copy-id username@hostname

Replace ‘username’ with your actual username and ‘hostname’ with your remote computer’s IP address or hostname.

Customizing SSH Server Settings

Edit the SSH server configuration file, usually found at /etc/ssh/sshd_config, to change settings like the default port, user permissions, and authentication methods. After adjustments, restart the SSH server to apply the changes.

Login Without a Password

After you set up your public key on the remote server, you can log in without a password. This is not only more convenient but also enhances security.

Advanced SSH Usage

SSH Client Options

When initiating an SSH connection, various options can modify how the connection behaves:

  • To specify a different port, use: ssh -p port_number.
  • To execute a command on the remote system and exit: ssh -t.
  • To mount a directory from your remote system on your local machine, look into SSHFS.

Security Measures

  • Disable password authentication once key-based is set up.
  • Restrict which users can log in using the AllowUsers and DenyUsers directives in the sshd_config file.
  • Change the default SSH port from 22 to a less commonly scanned port.

Remote GUI Access

SSH isn’t limited to the command line; you can use it to run graphical applications remotely with X11 Forwarding. On your local SSH command include -X to enable this:

ssh -X username@hostname

Make sure the SSH server is configured to allow X11 Forwarding.

Conclusion

SSH is a powerful tool that’s crucial for remote system administration, cloud computing, and more. By following the steps in this guide, you’ll be able to establish a secure connection to any remote computer with ease, involve in key-based authentication, and tweak your SSH settings for both convenience and heightened security.