Almost every real Linux server you will touch in your career lives in a data center or the cloud, and you will manage it over the network. The tool for that is SSH, the Secure Shell. In this advanced lesson you learn how to connect to remote machines, authenticate with keys instead of passwords, copy files with scp, and make daily remote work fast and safe.
SSH gives you an encrypted terminal session on another machine. The basic form is ssh user@host, where host is a hostname or IP address:
ssh deploy@203.0.113.10
ssh -p 2222 deploy@example.com # non-default port
ssh deploy@example.com 'uptime' # run one command and exitThe first time you connect, SSH shows the server's key fingerprint and asks you to confirm it. After you accept, the fingerprint is stored in ~/.ssh/known_hosts, and SSH will warn you loudly if it ever changes, which protects you against man-in-the-middle attacks.
Passwords over SSH work, but keys are more secure and more convenient. You generate a key pair locally: the private key stays on your laptop, and the public key is copied to the server.
ssh-keygen -t ed25519 -C "you@example.com"
ssh-copy-id deploy@example.com
ssh deploy@example.com # now logs in without a passwordProtect the private key with a passphrase when prompted. On servers you control, consider disabling password authentication entirely in /etc/ssh/sshd_config by setting PasswordAuthentication no, which shuts down brute-force attacks.
scp uses the SSH connection to copy files between machines. The syntax mirrors cp, with remote paths written as user@host:path:
scp report.pdf deploy@example.com:/var/www/files/
scp deploy@example.com:/var/log/nginx/access.log .
scp -r ./site deploy@example.com:/var/www/ # copy a directoryFor large or repeated transfers, rsync -avz over SSH is usually better because it only sends the differences, but scp remains the quickest tool for one-off copies.
Typing full connection strings gets old fast. The file ~/.ssh/config lets you define short, memorable aliases:
Host web
HostName 203.0.113.10
User deploy
Port 2222
IdentityFile ~/.ssh/id_ed25519
Now ssh web and scp file.txt web:/tmp/ just work. The config file supports dozens of options, including ForwardAgent for jumping between servers and LocalForward for tunneling ports to services like remote databases.
Two habits will save you repeatedly. First, run long tasks inside tmux or screen so that a dropped connection does not kill the job; reconnect and reattach with tmux attach. Second, before editing firewall rules or sshd_config remotely, keep a second SSH session open. If your change locks you out, the surviving session is your lifeline to undo it.
Congratulations, you have completed the Linux Command Line course. A great next step is our Next.js course, where you can put a Linux server to work hosting a modern web application.