How to Use the ssh Command for Remote Server Access in Ubuntu

If you rent a cloud server or have a headless Raspberry Pi sitting in a closet, you cannot simply plug a monitor and keyboard into it every time you need to make a configuration change. You need a secure way to log into that remote machine over the network. The industry standard for this is SSH (Secure Shell).

The ssh command allows you to open a terminal session on a remote Linux server as if you were sitting directly in front of it. All data transmitted between your local computer and the remote server is heavily encrypted, preventing anyone on the network from intercepting your passwords or commands.

Basic SSH Syntax

To connect to a remote server, you need three pieces of information: the ssh command itself, the username you want to log in as, and the IP address (or domain name) of the server.

The basic syntax looks like this:

ssh username@ip_address

For example, if your username is admin and your server’s IP address is 192.168.1.50, you would type:

ssh [email protected]

Handling the First Connection

The very first time you connect to a new server, SSH will stop and display a warning message that looks like this:

“The authenticity of host ‘192.168.1.50 (192.168.1.50)’ can’t be established. ECDSA key fingerprint is SHA256:xxxyyyzzz. Are you sure you want to continue connecting (yes/no/[fingerprint])?”

This is a security feature. Your local computer is telling you that it has never seen this server before and wants to confirm it is the correct machine. Type yes and press Enter.

Your computer will save the server’s unique fingerprint to a hidden file named ~/.ssh/known_hosts. The next time you connect, you will not see this warning. However, if the fingerprint ever changes in the future (which could indicate a hacker intercepting your connection), SSH will aggressively block the connection and warn you.

Entering Your Password

After accepting the fingerprint, SSH will prompt you for the remote user’s password.

[email protected]'s password: 

When you type your password in a Linux terminal, no characters, stars, or dots will appear on the screen. This is normal. Type your password blindly and press Enter.

If the password is correct, your terminal prompt will change. Instead of showing your local computer’s name, it will now display the remote server’s name, indicating that you are successfully logged in and any command you type will be executed on the remote machine.

Connecting Using a Custom Port

By default, SSH always attempts to connect over Port 22. However, many system administrators change the SSH port to a random number (like 2244) to reduce automated bot attacks.

If your server uses a non-standard port, the basic command will fail. You must use the -p flag to specify the correct port:

ssh -p 2244 [email protected]

How to Disconnect

When you have finished configuring your remote server, do not simply close the terminal window. You should properly close the encrypted connection.

Type exit or logout and press Enter (or press Ctrl + D). The terminal will display “Connection closed” and return you to your local computer’s prompt.

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.