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
- Use `ssh -v` for diagnostics.
- Keep private keys protected.
- Separate network failures from authentication failures.
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
SSH rejected your login because no key you offered was accepted by the server.
Connection refusedYou reached the machine, but nothing was listening on that port — or a firewall said no.
The commands behind it
Log into remote machines, run remote commands, use keys instead of passwords, and tunnel ports.
scpThe quickest way to move a file to or from a remote machine.
rsyncSync directories locally or over SSH, transferring only what changed.
Concepts involved: SSH key
More how-to guides
See how much space is left, and find out what is using it.
Extract a .tar.gz archiveUnpack tar.gz, tar.bz2, tar.xz and zip archives from the command line.
Free a port that is already in useFind which process holds a port and stop it cleanly.
Find and replace text in filesReplace text in one file or across a whole project, safely.