How to Connect to a Remote Server Using SSH
The procedure for connecting to a remote server varies depending on the type of server and operating system used. SSH, on the other hand, is one of the most widely used methods for connecting to and managing a remote server.
This guide demonstrates how to use SSH to access and operate a remote server. It assumes you already know the IP address of the remote server to which you want to connect.
SSH is a client-server program. This implies that the SSH server(a.k.a ssh daemon or
sshd) software must be installed, enabled, and accessible on the remote server on a certain port(
22 by default). The client which must be installed on your local computer makes a request to the server to establish a connection as explained below.
To successfully connect to a remote server via ssh:
- you must have a user account on the remote server or use an existing account,
- the ssh server must be configured to allow remote ssh connections to the account, and
- you must have valid login credentials to authenticate with.
Using SSH Password Authentication
On your local machine, open a terminal or command prompt. Then run the ssh command(ssh client) to establish a connection to the remote server. For example, to connect to an SSH server with an IP address
192.168.56.5, you could enter the following command in your terminal:
Remember to replace “
username” with your actual username on the remote server. If this is your first time connecting to the server, you may be prompted to accept the server’s fingerprint or provide authentication credentials such as a password. Follow the prompts to finish the authentication procedure.
Once you are authenticated, you can use the terminal on your local machine to administer the remote server by running commands on it.
If the ssh server on the remote server is listening on a different port other than the default,
9050 in this example, you can use the
-p flag to specify the port to connect to:
$ssh -p 9050 email@example.com
Note: In most cases, the ssh server is by default configured to use password authentication. But it can also be configured to only accept passwordless authentication using ssh keys(public-private key combination). You can learn more about ssh passwordless login here.
Using ssh Key Authentication
If the ssh server expects authentication using ssh keys, you can specify the identity or private key using the
-i flag, as shown. Replace
.ssh/my-private-key with the path to your private key.
$ssh -i .ssh/id_rsa firstname.lastname@example.org OR $ssh -i .ssh/my-private-key email@example.com
For more usage options, see the ssh man page:
Remember that depending on the remote server’s operating system and settings, the particular methods and syntax for connecting to it may vary. But most servers support and are configured to use ssh. Use the comment form below to find out more or ask questions.