Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
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.

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

The shortcut

For any remote-access question ask "does this travel over SSH?" If yes, it is encrypted and uses your keys. If no, like FTP, it is a plain-text risk that you should replace.

Locking down web1Step 1 of 4
  1. Create and install a key

    ssh-keygen -t ed25519, then ssh-copy-id deploy@web1.example.com.

The trap: disabling passwords before confirming key login works, and locking yourself out of the server.

Drills

Answer fast — trust the rule.

quick drill

Which key goes into the server's ~/.ssh/authorized_keys?

quick drill

What does SFTP run on top of?

quick drill

SSH warns that the remote host key has changed. What should you do?

quick drill

Why avoid classic FTP for deployments?

Remember

  • Use keys, not passwords: the private key stays home, the public key travels.
  • Shortcut: "does it travel over SSH?" If not, replace it.
  • Trap: disabling passwords before testing key login in a fresh session.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainLock down a new server

A new server currently allows password logins over SSH and runs an FTP server for deployments. Explain how you would switch to key-based access and secure file transfer without locking yourself out.