SSH in Linux: log in to a remote server and use keys
Updated July 3, 2026
ssh opens a secure session on a remote server over the network.
Syntax
ssh user@hostCommon cases
ssh alice@server # log in to the server
ssh -p 2222 alice@server # a non-standard port
ssh-keygen -t ed25519 # create a key pair
ssh-copy-id alice@server # put your key on the server
scp file.txt alice@server:~ # copy a file to the server
scp alice@server:~/log.txt . # and backHow it works: log in with a key, not a password
A key pair is a private key (kept only by you, in
~/.ssh/) and a public key (placed on the server). You sign a challenge from the server with the private key, and the server checks the signature with the public key - so login needs no password and is safer.ssh-copy-idputs the public key into~/.ssh/authorized_keyson the server. Never show or copy the private key to anyone. Servers you use often go in~/.ssh/config, so you type a short name instead of a long line.
In the book
This topic is covered in full in the chapter SSH and remote management.