GNU/Linux Secure Shell (SSH) Connecting to a remote server


Example

To connect to a server we must use SSH on the client as follows,

# ssh -p port user@server-address
  • port - The listening ssh port of the server (default port 22).
  • user - Must be an existing user on the server with SSH privileges.
  • server address - The IP/Domain of the server.

For a real world example lets pretend that you're making a website. The company you chose to host your site tells you that the server is located at web-servers.com on a custom port of 2020 and your account name usr1 has been chosen to create a user on the server with SSH privileges. In this case the SSH command used would be as such

# ssh -p 2020 usr1@web-servers.com

If account name on the remote system is the same as the one one the local client you may leave the user name off. So if you are usr1 on both systems then you my simply use web-servers.com instead of usr1@web-servers.com.

When a server you want to connect to is not directly accessible to you, you can try using ProxyJump switch to connect to it through another server which is accessible to you and can connect to the desired server.

# ssh -J usr1@10.0.0.1:2020 usr2@10.0.0.2 -p 2222

This will let you connect to the server 10.0.0.2 (running ssh on port 2222) through server at 10.0.0.1 (running ssh on port 2020). You will need to have accounts on both servers of course. Also note that the -J switch is introduced in OpenSSH version 7.3.