Start a Project

How To Use SSH To Connect To A Remote Server In Linux

What Is SSH?

Secure Shell, sometimes referred to as Secure Socket Shell, is a protocol that allows you to connect securely to a remote computer or a server by using a text-based interface.

When a secure SSH connection is established, a shell session will be started, and you will be able to manipulate the server by typing commands within the client on your local computer.

You can use SSH keys to identify trusted computers without the need for passwords and to interact with your servers.

SSH is encrypted with Secure Sockets Layer (SSL), which makes it difficult for these communications to be intercepted and read.

How to Install an OpenSSH Client

Many Linux distributions already have an SSH client, run the following command to install the OpenSSH client on your Linux computer:

  1. sudo apt-get install openssh-client
  2. Type in your superuser password when asked.
  3. Hit Enter to complete the installation.

you can check if the SSH server is running on the machine by typing this command:

sudo service ssh status

How To Create SSH Keys

SSH keys should be generated on the computer you wish to log in from.

Enter the following into the command line:

ssh-keygen -t rsa

Press enter multiple times to accept the defaults. Your keys will be generated at ~/.ssh/id_rsa.pub and ~/.ssh/id_rsa.

Switch into the .ssh directory using the command given below:

cd ~/.ssh

Look at the permissions of the files using the command given below:

ls -l

the id_rsa file should be readable and writable only to the owner to keep it secret.

How to Connect via SSH

ssh your_username@host_ip_address

And hit Enter.

NOTE: The default port is 22 if nobody changed the configuration in the sshd_config file. You may also just append the port number after the host IP address.

Here is the example of a connection request using the OpenSSH client. We will specify the customized port number as well:

ssh your_username@host_ip_address -p 18765

How to Connect With An SSH Client Using An SSH Key


Set the permissions for your private key file (.pem) to 400 using a command like the one below.

chmod 400 mykey.pem

Command to access a remote server using a pem file:

ssh -i mykey.pem your_username@host_ip_address

You are now able to manage and control a remote machine using your terminal. If you have trouble connecting to a remote server, make sure that:

Conclusion

As you will use the various options, you will find more advanced features that can make your life easier. SSH is most popular because it is secure, light-weight.

For further any help or query, please contact us.

Exit mobile version