Skip to the workspace
Pebellslearn by building
Networking & Protocols  ›  Capstone Project

SSH and SFTP — Secure Remote Access

SSH 12 minSSH gives encrypted remote access using a key pair whose private half stays with you, and file transfer should use SFTP, scp or rsync over SSH instead of plain FTP.

devops / SSH and SFTP — Secure Remote Access

Explore each scene at your own pace.

01 · The rule

The rule

SSH and SFTP — Secure Remote Access

Every task on web1 in this course began with "SSH in". SSH is the encrypted door to your servers, and how you set it up decides whether that door is easy for you and hard for everyone else.

The rule

Use keys, not passwords: the private key stays home, the public key travels.

SSH (Secure Shell) gives you an encrypted terminal on a remote machine, normally on port 22. Key-based login works with a key pair:

  • The private key stays on your laptop, protected by a passphrase. Never copy or share it.
  • The public key is placed on the server, in ~/.ssh/authorized_keys of the account you log in as.
ssh-keygen -t ed25519 -C "you@laptop"        # create a key pair
ssh-copy-id deploy@web1.example.com          # install the public key on the server
ssh deploy@web1.example.com                  # log in with the key

A ~/.ssh/config entry saves typing:

Host web1
    HostName web1.example.com
    User deploy
    IdentityFile ~/.ssh/id_ed25519

Now ssh web1 is enough. The first time you connect, SSH records the server's host key in ~/.ssh/known_hosts. If that key later changes, SSH warns loudly: it could be a rebuilt server, or someone intercepting you. Find out which before continuing.

Once keys work, harden the server in /etc/ssh/sshd_config with PasswordAuthentication no and PermitRootLogin no, then reload sshd.

Moving files. Old FTP sends passwords and data unencrypted, so avoid it. SFTP is a file-transfer protocol that runs inside SSH, using the same port and keys. scp also copies over SSH, and rsync over SSH copies only what changed.

sftp web1                                   # interactive transfers
scp release.tar.gz web1:/srv/releases/      # copy one file
Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.