SSH Tutorial for Beginners From First Login to Key Auth
Connect to a server with SSH, check its host key, set up key authentication, run remote commands, copy files and shorten it all with a config file.

SSH is how most Linux servers are reached, and the first session usually goes: type the command from a tutorial, answer yes to a question you do not understand, paste a password, and stay logged in with no idea what was set up. This tutorial goes through the same path, explaining each step, ending with key login and a short alias. Details of each part are in the other posts of the SSH guide.
Commands are for OpenSSH 10.0 on Debian 13, both as client and server. Other Linux distributions and macOS use OpenSSH too.
Step 1: connect
ssh [email protected]This connects to port 22 as the user alex. If you omit the user, SSH uses your local user name. On the first connection you see:
The authenticity of host 'server.example.test (203.0.113.10)' can't be established.
ED25519 key fingerprint is SHA256:...
Are you sure you want to continue connecting (yes/no/[fingerprint])?
This is the server proving who it is. If you can, compare the fingerprint with one the provider gives you (a cloud console often shows it); answering yes stores the key in ~/.ssh/known_hosts, and later connections are checked against it. A later warning that REMOTE HOST IDENTIFICATION HAS CHANGED means the key differs, which is either a reinstalled server or an attack. Do not delete the line without finding out which.
Step 2: make a key pair
ssh-keygen -t ed25519 -C "alex@laptop"Accept the default path (~/.ssh/id_ed25519) and set a passphrase. This creates a private key, which never leaves your machine, and a public key ending in .pub, which you give to servers. The details are in generating SSH keys.
Step 3: install the public key
ssh-copy-id [email protected]
ssh [email protected]The first command logs in with the password one last time and appends your public key to the server's ~/.ssh/authorized_keys. After that the second logs you in with the key. If it still asks for a password, fixing key authentication lists the causes.
Step 4: run commands without a shell
ssh [email protected] 'uptime'
ssh [email protected] 'df -h /; free -m'
echo $?The quoted string runs on the server, and its output comes back. The exit status of ssh is the remote command's, so scripts can test it. Quote the command so your local shell does not expand wildcards and variables first.
Step 5: copy files
scp report.txt [email protected]:/tmp/
scp [email protected]:/var/log/app.log .
rsync -avz --progress project/ [email protected]:/srv/project/Both use SSH underneath. scp is fine for single files; rsync is better for directories and repeated syncs, since it sends only changes. Note that the trailing slash on project/ decides whether the folder or its contents are copied.
Step 6: shorten it with a config
Host web
HostName server.example.test
User alex
IdentityFile ~/.ssh/id_ed25519
ssh web
scp report.txt web:/tmp/Every tool that uses SSH reads this file. The options are covered in the SSH config file.
When a session hangs
If the connection freezes, type Enter, then ~. (tilde and a dot) to end it without closing the terminal. Keep sessions alive across flaky networks with ServerAliveInterval 60 in your config, and use tmux on the server so work survives a disconnect.
What the host key prompt is protecting
The first time you connect, SSH shows the server's key fingerprint and asks whether to trust it. That prompt is the only defense against someone answering for the server. If you accept without checking, the key is stored in ~/.ssh/known_hosts, and every later connection compares against it. A mismatch later produces a loud warning, which usually means the server was rebuilt and not that you are under attack, but you must treat it as a question to answer and not an error to silence. To check, compare the fingerprint on the screen with one the administrator publishes, or run ssh-keygen -lf on the host's public key from a trusted channel.
ssh-keygen -lf ~/.ssh/id_ed25519.pub
ssh-keygen -lf ~/.ssh/id_ed25519.pub -E md5256 SHA256:HNK3+lbo8SKTvxmICNzpIEHFTFOYb87sEsKNMUNypuE alex@laptop (ED25519)
256 MD5:6e:aa:c4:36:ef:d1:b8:e8:70:5e:2f:64:8e:8e:45:5b alex@laptop (ED25519)
The first line is the modern SHA-256 form, the same one the connection prompt prints. The older MD5 form appears in some documentation and web consoles. Both come from the same key, here a throwaway ed25519 key created for this example with OpenSSH 10.3. If you see a fingerprint you do not recognize on a server you have used before, stop and ask why before typing a password.
What each file in ~/.ssh is for
A handful of files sit in the directory, and mixing them up is a common source of trouble. The private key, such as id_ed25519, never leaves your machine. The public key, id_ed25519.pub, is what you copy to servers. known_hosts records the servers you trust. authorized_keys exists on the server and lists the public keys allowed to log in. config holds your shortcuts. The server-side file matters most for troubleshooting: a login that fails after you copied the key is usually a permissions problem on the server, because sshd refuses to read an authorized_keys that others can write.
Running one command and getting its status back
An SSH command returns the exit status of the remote command, which makes it usable in scripts and conditions. Quote the remote command so your local shell does not expand it first, and use -o BatchMode=yes in automation so a missing key fails at once instead of waiting for a password that nobody will type.
ssh -o BatchMode=yes web 'test -d /var/www/app'; echo "status $?"
ssh web 'df -h / | tail -n 1'A status of 255 means SSH itself failed, such as a connection refusal or an authentication failure, and other values come from the remote command. That separation lets a deploy script treat a network problem differently from a failed check. Wrap anything that must not hang in timeout, because a connection to a server that has dropped off the network can wait a long time for the TCP stack to give up.
Troubleshooting a first connection
When the first connection fails, the message tells you where. "Connection refused" means the machine answered and nothing listens on that port. "Connection timed out" means no answer, usually a firewall or a wrong address. "Permission denied (publickey)" means the server is there and your key was not accepted. "Host key verification failed" means the key changed since you last connected. Run ssh -v for details and read upward from the last line. Each message points to a different part of the chain, so name the failure before you change anything.
Next steps and limits
Once key login works, disable password logins on the server (PasswordAuthentication no in a file under /etc/ssh/sshd_config.d/), after confirming a second session can still log in. SSH is a protocol with tunneling, jump hosts and more, which later posts cover. The tool is documented in ssh(1) and the server in sshd_config(5).


