How to connect remotely using SSH?
Remote access and control of computers is a necessity. Depending on your operating system, there are different ways to establish a remote connection with a computer, and the two most commonly used protocols are:
- SSH for Linux-based systems
- RDP for Windows-based systems
What is SSH?
SSH (Secure Shell) is a network protocol that allows two computers to establish an encrypted connection and share data. Once an SSH connection is established, you can enter commands in the client application on your local computer to operate the server remotely.
To establish an SSH remote connection, you must install two components: the client-side and server-side components. The client-side component is an application installed on your computer, enabling you to connect to another computer or server. On the other hand, the server-side component, known as the SSH daemon, operates in the background and handles connection requests from clients.
How to install the SSH client-side component?
Many Linux distributions already have an SSH client (openssh-client) pre-installed. To check if the SSH client is available, you can:
- Load the SSH terminal. You can search for “terminal” or press CTRL + ALT + T on your keyboard.
- Type SSH in the terminal and press Enter.
- If the client is installed, you will receive a response similar to the following:
[-D [bind_address:]port] [-E log_file] [-e escape_char]
[-F configfile] [-I pkcs11] [-i identity_file]
[-J [user@]host[:port]] [-L address] [-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port] [-Q query_option] [-R address] [-S ctl_path] [-W host:port] [-w local_tun[:remote_tun]]
If you don’t get the above response, then you need to install the OpenSSH client:
- Run the following command to install the OpenSSH client on your computer:
sudo apt-get install openssh-client
- Enter your administrator password when prompted.
- Press Enter to complete the installation.
How to install the SSH server-side component?
You need to check if the remote computer that will accept SSH connections has the OpenSSH server-side component (openssh-server) installed:
- Open the terminal on the server computer. You can search for “terminal” or press CTRL + ALT + T on your keyboard.
ssh localhostand press Enter.
- For systems without an SSH server installed, you will see a message similar to the following:
This means you need to install the OpenSSH server-side component. Keep the terminal open and:
ssh: connect to host localhost port 22: Connection refused username@host:~$
- Run the following command to install the SSH server:
sudo apt-get install openssh-server
- Enter your administrator password when prompted.
- When prompted with disk space, enter Y to continue with the installation.
You can check if the SSH server-side component is running on the computer by typing the following command:
sudo service ssh status
If it’s running properly, you will see a response in the terminal similar to the following:
• ssh.service – OpenBSD Secure Shell server
Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enab
Active: active (running) since Fr 2018-03-12 10:53:44 CET; 1min 22s ago Process: 1174 ExecReload=/bin/kill -HUP $MAINPID (code=exited, status=0/SUCCES)
Main PID: 3165 (sshd)
Changing the default port for SSH connections
Additionally, you can edit the SSH daemon to change the default port for SSH connections. In the terminal prompt, run the following command:
sudo nano /etc/ssh/sshd_config
The configuration file will open in the editor of your choice, and in this case, we’ll use Nano as an example. If Nano is not installed, run the following command:
sudo apt-get install nano
Note that every time you make any changes to the sshd_config file by running the above command, you’ll need to restart the SSH service:
sudo service ssh restart
How to establish an SSH connection
- Open the SSH terminal on your computer and run the following command:
ssh your_username@host_ip_address. If the username on your local computer matches the username on the server you’re trying to connect to, you can simply type:
ssh host_ip_addressand press Enter.
- Enter your password and press Enter. Note that you won’t see any feedback on the screen as you type. If you need to paste the password, make sure it’s stored securely and not in a plain text file.
- When connecting to the server for the first time, it will ask if you want to continue connecting. Simply type “yes” and press Enter. This message only appears once because the remote server is not recognized by your local computer.
- You have now added the ECDSA key fingerprint and are connected to the remotecomputer via SSH. You can now use the terminal on your local computer to execute commands on the remote server.
SSH provides a secure and encrypted method for remote access and control of computers. By following the steps outlined above, you can install and configure the SSH client-side and server-side components, and establish an SSH connection to remotely access and operate a computer or server.