↑↓ move Enter open Esc close

How to Connect to a Linux Server with SSH

Connect securely to a remote Linux host using username, hostname, port and SSH key.

SSH opens an encrypted remote shell. The basic form is username plus hostname, with options for ports, keys and diagnostics.

Step by step

1 Connect normally

$ ssh user@server.example.com

The default SSH service uses TCP port 22 unless configured otherwise.

2 Use another port

$ ssh -p 2222 user@server.example.com

Lowercase -p selects the destination port.

3 Use a key

$ ssh -i ~/.ssh/id_ed25519 user@server

The -i option selects a private identity file.

4 Run one remote command

$ ssh user@server "uname -a"

SSH can execute a command and then exit.

Tips worth knowing

Frequently asked questions

What is the SSH command format?

Use `ssh user@hostname`, optionally with `-p PORT` and `-i KEY`.

Why do I get Permission denied (publickey)?

The server rejected the key or account/key configuration.

If it goes wrong

The commands behind it

Concepts involved: SSH key

More how-to guides