Knowledgebase

Find frequently asked questions and setup guides by searching or by browsing the categories.

The Command

ssh user@your_server_ip

Replace user with your account on the server and your_server_ip with its IP address or host name. Run the command in a terminal on your own computer, not on the server. Most current desktop systems ship the OpenSSH client, so ssh is usually already there; type ssh -V to check its version. If you prefer a graphical program, see how to use PuTTY to SSH into a server.

Connect on Another Port

SSH listens on port 22 unless someone changed it. For another port, add -p (lowercase, unlike scp):

ssh -p 2222 user@your_server_ip

How to move the server to a new port is covered in how to change the SSH port.

The First Connection

On the first connection ssh says that the authenticity of the host cannot be established, prints the server's key fingerprint, and asks whether you want to continue. This is ssh asking you to confirm that you are talking to the right machine.

The careful way: open the server console in your provider's control panel and run

ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub

If the prompt names another key type, such as ECDSA, use that type's file instead. If the fingerprint matches the one in your terminal, type yes. ssh stores the key in ~/.ssh/known_hosts and checks it on every later connection. If it ever changes, ssh stops with a warning; see host key verification failed.

Log In with a Password or a Key

With password login, ssh asks for the password. Nothing appears on the screen while you type; that is normal. Press Enter when done.

With an SSH key, ssh tries your default key files, such as ~/.ssh/id_ed25519, and any keys loaded in an agent. To use a particular key, name it with -i:

ssh -i ~/.ssh/id_ed25519 user@your_server_ip

Keys are safer than passwords and save typing. Create one with ssh-keygen, then put it on the server with ssh-copy-id.

Run One Command and Return

Put the command after the address. ssh runs it, prints the output, and disconnects:

ssh user@your_server_ip 'df -h /'

Commands that need a terminal, such as top or a sudo password prompt, need -t:

ssh -t user@your_server_ip 'sudo systemctl status nginx'

Useful Options

OptionWhat it does
-p 2222Connects to another port.
-i keyUses a specific private key.
-vPrints debug output; -vv prints more.
-tForces a terminal for one command.
-LForwards a local port.

Log Out

Type exit or press Ctrl+D. If a session hangs because the network dropped, press Enter, then type ~. (tilde, then a dot) to close it from your side. Work that must keep running after you disconnect belongs in a terminal multiplexer; see the tmux cheat sheet.

When It Does Not Connect

To stop typing the user, address, and port each time, give the server a short name in the SSH config file.

Was this answer helpful?
Loading...