Ravindra BagaleCourses & study guides मराठी Track your progress

AWS Cloud

SSH Deep Dive: Keys, ~/.ssh/config, ssh-agent, Tunnels, Jump Hosts, scp, rsync and sftp

SSH is how you reach almost every Linux server. In earlier chapters you logged in with ssh; now we go deep: key types and ssh-keygen, copying keys with ssh-copy-id, the ~/.ssh/config file, ssh-agent, local, remote and dynamic tunnels, jump hosts with ProxyJump, and moving files with scp, rsync and sftp. The examples use the safe defaults you will see in real teams.

In this chapter

  • Create and protect SSH keys
  • Install keys on servers with ssh-copy-id
  • Write ~/.ssh/config to save typing
  • Use ssh-agent and agent forwarding safely
  • Build local, remote and dynamic tunnels and use jump hosts
  • Copy files with scp, rsync and sftp

1. An everyday example: a society gate and your own key

Your housing society gives each flat owner a key. The guard keeps a list of which keys may open the gate. To reach a flat in the back wing, you go through the main gate first. When you visit often, you note the flat number and wing in your diary so you do not ask every time.

Your private key = the key in your pocket (never share). Public key = the copy the guard keeps (authorized_keys). Main gate = jump host (bastion). Diary = ~/.ssh/config. Keeping the key in your hand while walking = ssh-agent.

How key login worksYour client connects to port 22 and checks the server's host key (known_hosts)The client offers your public keyThe server finds it in ~/.ssh/authorized_keysThe server sends a challengeYour private key signs it (agent or key file)The server verifies the signature and logs you in
The private key never leaves your machine.

2. ssh-keygen: make a key pair

There are two identities in an SSH login. The host key helps your computer check which server it reached. Your user key helps the server check which account can log in. When you create a pair, keep the private file on your own computer. The public file ending in .pub is the part the server can store in the intended user’s authorized_keys. Match the user name in the login command to the account that has that public key. A valid key for your account can still be rejected if you try to sign in as a different user.

Passwords can be guessed and are often disabled on servers. Keys are stronger and can be automated.

ssh-keygen -t ed25519 -C 'comment' makes a modern key: ~/.ssh/id_ed25519 (private) and id_ed25519.pub (public). Use a passphrase. -f sets the file name. Use -t rsa -b 4096 only for old systems. ssh-keygen -lf FILE shows the fingerprint; -p changes the passphrase.

  1. New key.
ssh-keygen -t ed25519 -C 'ravi@laptop'

Output:

Your identification has been saved in /home/ravi/.ssh/id_ed25519
The key fingerprint is: SHA256:Zr1x... ravi@laptop

Two files created.

  1. Separate key for CI.
ssh-keygen -t ed25519 -f ~/.ssh/deploy_ci -N '' -C 'ci-deploy'

Output:

Your public key has been saved in /home/ravi/.ssh/deploy_ci.pub

No passphrase for a robot; restrict it on the server.

  1. Fingerprint.
ssh-keygen -lf ~/.ssh/id_ed25519.pub

Output:

256 SHA256:Zr1x... ravi@laptop (ED25519)

Compare with what the admin sees.

3. Key permissions and authorized_keys

SSH refuses keys that other users can read. Wrong permissions are the top reason key login fails.

~/.ssh must be 700, private keys 600, authorized_keys 600, home not group-writable. authorized_keys has one public key per line and may start with options like from="10.0.0.0/8",command="...",no-port-forwarding.

  1. Fix permissions.
chmod 700 ~/.ssh && chmod 600 ~/.ssh/id_ed25519 ~/.ssh/authorized_keys && ls -ld ~/.ssh

Output:

drwx------ 2 ravi ravi 4096 ~/.ssh

Correct.

  1. Restrict a CI key.
cat ~/.ssh/authorized_keys

Output:

from="10.0.9.0/24",no-agent-forwarding,no-pty ssh-ed25519 AAAAC3... ci-deploy

Only from CI subnet, no shell tty.

  1. SELinux context.
restorecon -Rv ~/.ssh

Output:

Relabeled /home/ravi/.ssh/authorized_keys

Needed if files were copied in oddly.

4. ssh-copy-id: install your key

Copying a key by hand risks broken lines and wrong permissions. ssh-copy-id does it right.

ssh-copy-id -i ~/.ssh/id_ed25519.pub user@host appends the key to the remote authorized_keys and fixes permissions. It needs one password login (or an existing key). In cloud, keys are usually set at launch instead.

  1. Copy.
ssh-copy-id -i ~/.ssh/id_ed25519.pub ravi@10.0.1.30

Output:

Number of key(s) added: 1
Now try logging into the machine

Done.

  1. Test with only that key.
ssh -i ~/.ssh/id_ed25519 -o PasswordAuthentication=no ravi@10.0.1.30 hostname

Output:

app-30

Key login works.

5. ssh options: -i, -p, -v, -o and running one command

You often need a different key, a different port, or to debug why login fails.

-i KEY chooses the key, -p PORT the port, -v/-vv/-vvv debug output, -o Option=value any config option, -t forces a tty. ssh host 'command' runs one command and returns. ~. on a new line kills a hung session.

  1. Other port.
ssh -p 2222 ravi@bastion.example.com

Output:

Last login: ...

sshd on 2222.

  1. One command.
ssh ravi@app-30 'uptime; df -h /'

Output:

10:02 up 41 days, load 0.21
/dev/nvme0n1p1 20G 11G 9G 55% /

Quick checks without a shell.

  1. Debug.
ssh -v ravi@app-30 2>&1 | grep -E 'Offering|Authenticated|denied'

Output:

debug1: Offering public key: /home/ravi/.ssh/id_ed25519 ED25519
debug1: Authenticated to app-30

See which key was used.

  1. Run on many servers.
for h in app-30 app-31; do ssh -o BatchMode=yes $h hostname; done

Output:

app-30
app-31

BatchMode fails instead of asking a password.

6. known_hosts and host key warnings

On the first connection to a lab server, read the fingerprint in the prompt. It is a short representation of the server’s host key. Compare it with the fingerprint supplied through your lab management console or another trusted channel. A match lets you recognise that key on future connections. If a rebuild changed the key, verify the new fingerprint and the machine’s identity before updating the saved entry. Keep troubleshooting user keys separate from this check: a host-key warning occurs while your client is deciding who is on the other end.

The host key proves you reached the real server, not an attacker. Rebuilt servers change it, and SSH warns you.

~/.ssh/known_hosts stores host keys. 'REMOTE HOST IDENTIFICATION HAS CHANGED' means the key differs. If you know the server was rebuilt, remove the old line with ssh-keygen -R host. ssh-keyscan host prints a host's keys (verify them out of band).

  1. The warning.
ssh ravi@10.0.1.30

Output:

@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
Offending ED25519 key in /home/ravi/.ssh/known_hosts:14

Stop and confirm the rebuild.

  1. Remove the old key.
ssh-keygen -R 10.0.1.30

Output:

# Host 10.0.1.30 found: line 14
/home/ravi/.ssh/known_hosts updated.

Next login asks to accept the new one.

  1. Pre-load for automation.
ssh-keyscan -t ed25519 git.example.com >> ~/.ssh/known_hosts

Output:

# git.example.com:22 SSH-2.0-OpenSSH_9.6

Verify fingerprint first.

7. ~/.ssh/config: save your settings

Typing ssh -i ~/.ssh/k -p 2222 ec2-user@15.1.2.3 many times a day is slow and error-prone.

Blocks start with Host ALIAS, then HostName, User, Port, IdentityFile, IdentitiesOnly yes, ProxyJump, ServerAliveInterval. Host * sets defaults for all. File must be 600. scp, rsync and git use these aliases too.

  1. A config file.
cat ~/.ssh/config

Output:

Host web1
  HostName 15.1.2.3
  User ec2-user
  IdentityFile ~/.ssh/aws_prod.pem
  IdentitiesOnly yes
Host *
  ServerAliveInterval 30

Now just: ssh web1

  1. Check what ssh will use.
ssh -G web1 | grep -E '^(hostname|user|identityfile)'

Output:

hostname 15.1.2.3
user ec2-user
identityfile ~/.ssh/aws_prod.pem

Final merged settings.

  1. Wildcards.
Host app-*
  User deploy
  ProxyJump bastion

Output:

(config)

All app hosts go via bastion.

8. ssh-agent and ssh-add

With a passphrase you would type it on every login. The agent holds the unlocked key in memory for the session.

eval "$(ssh-agent -s)" starts it. ssh-add ~/.ssh/id_ed25519 loads a key; ssh-add -l lists; ssh-add -D removes all; ssh-add -t 3600 sets a lifetime. Agent forwarding (ssh -A) lets a remote host use your agent; only use it on hosts you trust, prefer ProxyJump.

  1. Start and add.
eval "$(ssh-agent -s)" && ssh-add -t 8h ~/.ssh/id_ed25519

Output:

Agent pid 4412
Identity added: /home/ravi/.ssh/id_ed25519 (ravi@laptop)
Lifetime set to 28800 seconds

Passphrase asked once.

  1. List.
ssh-add -l

Output:

256 SHA256:Zr1x... ravi@laptop (ED25519)

Loaded.

  1. Too many keys.
ssh web1

Output:

Received disconnect: Too many authentication failures

Agent offers 6 keys; set IdentitiesOnly yes.

9. ProxyJump: reach private servers through a bastion

Private servers have no public IP. You must go through a jump host (bastion) without copying your key to it.

ssh -J user@bastion user@private connects through bastion; your key stays local. Chain with commas: -J b1,b2. In config: ProxyJump bastion. Old way: ProxyCommand ssh -W %h:%p bastion.

  1. One jump.
ssh -J ec2-user@bastion.example.com ec2-user@10.0.3.40

Output:

[ec2-user@db-40 ~]$

Inside the private subnet.

  1. Config way.
Host bastion
  HostName bastion.example.com
  User ec2-user
Host db40
  HostName 10.0.3.40
  ProxyJump bastion

Output:

ssh db40

Same, shorter.

  1. scp through the jump.
scp -J bastion backup.sql db40:/tmp/

Output:

backup.sql 100% 40MB 22MB/s

Works with rsync too via config.

10. Local port forwarding: ssh -L

A database or admin page listens only inside a private network. -L brings it to your laptop safely.

ssh -L LOCALPORT:TARGET:TARGETPORT host. Traffic to localhost:LOCALPORT goes through host to TARGET:TARGETPORT. Add -N (no command) and -f (background) for a tunnel only. Bind only to 127.0.0.1 (the default).

  1. Reach a private Postgres.
ssh -N -L 15432:db.internal:5432 bastion

Output:

(waits)

Now psql -h localhost -p 15432 on the laptop.

  1. Admin page.
ssh -fN -L 8080:127.0.0.1:8080 web1 && curl -sI http://localhost:8080

Output:

HTTP/1.1 200 OK

App bound to localhost on web1.

  1. Port in use.
ssh -N -L 8080:127.0.0.1:8080 web1

Output:

bind [127.0.0.1]:8080: Address already in use

Pick another local port.

11. Remote (-R) and dynamic (-D) forwarding

-R lets a remote server reach something on your side (like a demo app). -D gives a SOCKS proxy to browse a private network.

ssh -R REMOTEPORT:localhost:LOCALPORT host opens REMOTEPORT on host that leads back to you. By default it binds to the server's localhost (GatewayPorts). ssh -D 1080 host makes a SOCKS5 proxy on localhost:1080.

  1. Share a local app.
ssh -N -R 9000:localhost:3000 web1

Output:

(waits)

On web1: curl localhost:9000 reaches your laptop's port 3000.

  1. SOCKS proxy.
ssh -N -D 1080 bastion &
curl --socks5-hostname localhost:1080 http://grafana.internal:3000/login -sI

Output:

HTTP/1.1 200 OK

Browse private hosts by name.

12. scp: simple copy

Read the two places in a copy command in order: source first, destination second. A plain path is on the computer where you run scp. An argument with user@host: before the path refers to the other computer. Download a harmless sample from your own lab server and give the local file a different name. Run ls -l locally and compare the size with the remote file. That check catches the common mix-up where the command was started inside the server terminal rather than on the laptop.

The quickest way to send one file to or from a server.

scp SRC DEST, where remote paths are host:path. -r for folders, -P PORT (capital P), -i KEY, -J jump. Modern OpenSSH runs scp over SFTP internally. For big or repeated copies, use rsync.

  1. Upload.
scp app.tar.gz web1:/tmp/

Output:

app.tar.gz 100% 18MB 30.1MB/s 00:00

Uses config alias.

  1. Download a folder.
scp -r web1:/var/log/nginx ./nginx-logs

Output:

access.log 100% 220MB
error.log 100% 3MB

Copied recursively.

  1. Custom port.
scp -P 2222 report.pdf ravi@bastion.example.com:~

Output:

report.pdf 100%

Capital P for scp.

scp in depth: upload, download, -r, -P, -i and server to server

You often need to put a file on a server or bring a log back to your laptop. scp does it over SSH, so it is encrypted and uses the same keys you already have.

scp copies files like cp, but one side is host:path. The first path is the source and the last path is the destination. Remote paths look like user@host:/path.

Common options

OptionWhat it does
-rCopy a folder and everything inside.
-P PORTSSH port (capital P; ssh uses small -p).
-i KEYUse this private key file.
-3Server to server copy through your machine.
-CCompress during transfer.
-pKeep times and modes.
-l KBITLimit bandwidth in Kbit/s.
  1. Upload: local file first, server last.
scp menu-diwali.pdf rohan@192.168.1.40:/var/www/cafe/

Output:

menu-diwali.pdf      100%  812KB  9.8MB/s   00:00

The file is now in /var/www/cafe/ on the server.

  1. Download: server first, local last.
scp rohan@192.168.1.40:/var/log/nginx/error.log ~/Downloads/

Output:

error.log            100%   64KB  7.1MB/s   00:00

A dot (.) as the last path means the current folder.

  1. A whole folder with -r.
scp -r invoices-oct rohan@192.168.1.40:~/backup/

Output:

inv-001.pdf  100%  ...
inv-002.pdf  100%  ...

Without -r you get "not a regular file".

  1. A custom port with -P.
scp -P 2022 db.sql.gz rohan@shop.example.in:/tmp/

Output:

db.sql.gz            100%   18MB  11MB/s   00:01

The server runs SSH on 2022, not 22.

  1. A key file with -i (cloud servers).
scp -i ~/keys/mumbai.pem app.jar ubuntu@13.233.10.5:/opt/app/

Output:

app.jar              100%   42MB  20MB/s   00:02

The .pem key must be chmod 600, or SSH refuses it.

  1. Server to server.
scp -3 old-db:/backup/shop.sql new-db:/restore/

Output:

shop.sql             100%  120MB  30MB/s   00:04

-3 sends the data through your laptop, so the two servers do not need keys for each other. Without -3 the first server connects straight to the second.

Practise this in the tasks below: Practice tasks

13. rsync: smart sync over SSH

rsync only sends what changed, can resume, and keeps permissions. It is the tool for deploys, backups and migrations.

rsync -avz SRC/ host:DEST/: -a archive (perms, times, links), -v verbose, -z compress. -n (--dry-run) shows what would happen. --delete removes extra files in DEST (careful). --progress, --partial, -e 'ssh -p 2222'. A trailing slash on SRC means 'contents of'.

OptionMeaning
-aArchive: keep perms, times, links
-zCompress in transit
-nDry run
--deleteMirror: remove extras
--excludeSkip a pattern
-PProgress + partial
  1. Dry run first.
rsync -avzn --delete ./site/ web1:/var/www/site/

Output:

deleting old.html
index.html
sent 1.2K bytes

Shows the delete before doing it.

  1. Real run.
rsync -avz --delete ./site/ web1:/var/www/site/

Output:

index.html
sent 4.8K bytes received 92 bytes

Only changes sent.

  1. Backup with excludes.
rsync -aP --exclude 'cache/' web1:/srv/data/ /backup/data/

Output:

data/big.bin 2.1G 100% 95MB/s

Resumable large copy.

  1. Slash matters.
rsync -a src web1:/opt/  vs  rsync -a src/ web1:/opt/

Output:

/opt/src/...  vs  /opt/...

With slash: contents only.

14. sftp: interactive file transfer

Partners and non-Linux users often get SFTP-only accounts. You browse and transfer without a shell.

sftp user@host opens a prompt with ls, cd, lcd, get, put, mkdir, rm, bye. -b batchfile runs commands from a file (for scripts). Servers can lock users into SFTP with ChrootDirectory and ForceCommand internal-sftp.

  1. Interactive.
sftp vendor@files.example.com
sftp> cd inbound
sftp> put invoice-oct.csv
sftp> bye

Output:

Uploading invoice-oct.csv to /inbound/invoice-oct.csv

Uploaded.

  1. Batch mode.
printf 'cd outbound\nget *.csv\n' > b.txt && sftp -b b.txt vendor@files.example.com

Output:

Fetching /outbound/orders.csv

Good for cron jobs.

15. Real examples from many industries

The same Linux skill shows up in every kind of company. Seeing it in many places helps you remember it.

Each row is a made-up team. It shows who uses this and how.

Team and cityHow they use itCommand
Vikram, IT services, PuneUses ProxyJump for all private serversssh -J bastion db40
Sarah, healthcare, BostonRestricts CI keys with from= optionsfrom="10.0.9.0/24" ssh-ed25519 ...
Yuki, gaming, Tokyorsync deploys with dry run firstrsync -avzn --delete ./build/ web1:/srv/
Carlos, retail, Mexico CitySFTP batch jobs with supplierssftp -b b.txt vendor@files
Nadia, bank, FrankfurtTunnels to private DBs for auditsssh -N -L 15432:db.internal:5432 bastion
Omkar, agri startup, SataraKeeps a tidy ~/.ssh/configssh -G web1

16. Common errors and how to fix them

Everyone hits these errors. Knowing the cause saves hours.

Read the exact message first. Then match it to a row below.

Error you seeWhy it happensHow to fix
Permission denied (publickey)Key not in authorized_keys, wrong user or wrong keyDebug which key is offered.
ssh -v user@host
UNPROTECTED PRIVATE KEY FILE!Private key readable by othersSet 600.
chmod 600 ~/.ssh/id_ed25519
REMOTE HOST IDENTIFICATION HAS CHANGEDHost key changed: rebuild or attackConfirm, then remove the old key.
ssh-keygen -R host
Too many authentication failuresAgent offered too many keysUse IdentitiesOnly with a chosen key.
ssh -o IdentitiesOnly=yes -i KEY host
Connection timed out (port 22)Security group/firewall blocks 22Allow your IP or use the bastion.
nc -zv -w 3 host 22
Could not open a connection to your authentication agentNo agent running in this shellStart it.
eval "$(ssh-agent -s)"
bind: Address already in use (tunnel)Local port busyChoose another local port.
ss -ltnp 'sport = :8080'
rsync: command not found (remote)rsync missing on the other sideInstall it there.
ssh web1 'sudo dnf install -y rsync'
scp: ssh: connect to host ... port 22: Connection refused with -pUsed -p instead of -Pscp uses capital -P.
scp -P 2222 file host:
channel 2: open failed: connect failed: Connection refusedTunnel target not listeningCheck target host:port from the SSH server.
ssh bastion 'nc -zv db.internal 5432'

17. Troubleshooting step by step

When SSH login fails, go from network to auth.

Go top to bottom. Stop at the first step that shows the problem.

  1. Port open?
nc -zv -w 3 host 22
  1. Right settings used?
ssh -G host | head
  1. Which key offered?
ssh -v host
  1. Permissions ok?
ls -la ~/.ssh
  1. Server log.
sudo journalctl -u sshd -n 30
  1. Key on server?
grep -c ssh-ed25519 ~/.ssh/authorized_keys

18. Lab 1: Keys, config and agent

Create a key, install it on a host (localhost works), and log in by alias.

A full hands-on lab. Run every step on a test Linux machine (an EC2 instance, a VM, or WSL).

  1. Create.
ssh-keygen -t ed25519 -f ~/.ssh/lab_key -C lab

Output:

Your identification has been saved
  1. Install on localhost.
ssh-copy-id -i ~/.ssh/lab_key.pub $USER@localhost

Output:

Number of key(s) added: 1
  1. Add a config alias.
printf 'Host lab\n  HostName localhost\n  IdentityFile ~/.ssh/lab_key\n  IdentitiesOnly yes\n' >> ~/.ssh/config; chmod 600 ~/.ssh/config

Output:

(no output)
  1. Load agent.
eval "$(ssh-agent -s)"; ssh-add ~/.ssh/lab_key

Output:

Identity added
  1. Log in.
ssh lab hostname

Output:

yourhost

19. Lab 2: Tunnel and sync

Reach a localhost-only web server through a tunnel and sync a folder with rsync.

A full hands-on lab. Run every step on a test Linux machine (an EC2 instance, a VM, or WSL).

  1. Start a private server.
python3 -m http.server 8001 --bind 127.0.0.1 &

Output:

Serving HTTP on 127.0.0.1 port 8001
  1. Tunnel to it.
ssh -fN -L 9001:127.0.0.1:8001 lab

Output:

(no output)
  1. Test.
curl -sI http://localhost:9001

Output:

HTTP/1.0 200 OK
  1. Dry-run sync.
mkdir -p /tmp/a && touch /tmp/a/f1 && rsync -avn /tmp/a/ lab:/tmp/b/

Output:

f1
  1. Real sync.
rsync -av /tmp/a/ lab:/tmp/b/

Output:

sent 120 bytes

Ravindra Bagale's Tip

Put every server in ~/.ssh/config with IdentitiesOnly yes and use ProxyJump instead of agent forwarding (-A). Your key never sits on the bastion, and a hacked bastion cannot use your agent.

20. Frequently asked questions

Q. ed25519 or RSA?

ed25519: shorter, faster, modern. RSA 4096 only for old systems.

Q. Can I share my private key with a teammate?

Never. Each person gets their own key.

Q. scp or rsync?

rsync for big, repeated or resumable copies.

Q. What does -N do?

No remote command; tunnel only.

Q. Is agent forwarding unsafe?

Root on the remote host can use your agent while connected.

Q. Why does rsync --delete scare people?

It removes files in the destination; always dry-run first.

Q. How to keep SSH from dropping?

ServerAliveInterval 30 in config.

Q. What is a bastion?

A hardened jump host that is the only SSH entry to a private network.

21. Interview questions and answers

Beginner level

Q. Create a modern key?

ssh-keygen -t ed25519.

Q. Copy key to server?

ssh-copy-id user@host.

Q. Copy a file to a server?

scp file host:/path.

Q. Permissions for private key?

600.

Mid level level

Q. Reach a private DB from laptop?

ssh -L 15432:db:5432 bastion.

Q. What is ProxyJump?

Connect through a jump host without copying keys there.

Q. Fix host key changed after rebuild?

ssh-keygen -R host, then reconnect and verify.

Q. rsync trailing slash?

SRC/ copies contents; SRC copies the folder itself.

Senior level

Q. Harden SSH on a fleet?

Keys only, no root login, AllowGroups, MFA/SSO certs, bastion, logging.

Q. Rotate a leaked key?

Remove from all authorized_keys (config mgmt), issue new key, audit logs.

Q. -L vs -R vs -D?

-L brings remote to local, -R exposes local on remote, -D SOCKS proxy.

Q. Why SSH certificates?

Short-lived signed keys; no authorized_keys sprawl.

Try at home

  1. Create a ~/.ssh/config with three hosts including one ProxyJump, and check each with ssh -G.
  2. Use rsync -avn to compare two folders and explain each line of output.

Practise this chapter

Interview questions and answers

Why can SSH reject a valid private key when you change the target username?

The server checks whether the corresponding public key is allowed for the requested account. A key installed for one account does not automatically apply to another. Check username, the public key location and the permitted SSH setup on the lab server.

Check your understanding

Choose an answer, then compare your reasoning with the explanation.

0 of 3 answered correctly
1. Which file should you install in the intended server account for public-key login?

Answer and explanation

C. The public key line in authorized_keys

The client keeps the private key and proves it can use it. The server uses the allowed public key to verify that proof.

2. Which key helps the client decide whether it reached the right server?

Answer and explanation

C. The server’s host key

The host key identifies the server. Compare its fingerprint using a separate trusted source before accepting it.

3. Which part of scp user@lab:report.txt ./report-copy.txt is remote?

Answer and explanation

A. The source report.txt on lab

The user and host prefix mark a remote path. The plain destination path is on the machine running scp.

Practice Tasks

Practice checks run in your browser. They check the answer for this exercise; they do not create resources or connect to your AWS account.

About this scenario

London Legal LLP is a law business in London. Oliver Hughes looks after its IT and cloud work. They count money in GBP and run their AWS resources in the eu-west-2 Region. In the tasks below you do real jobs for them using what this lesson teaches. All names, account IDs, IP addresses and numbers are made up for practice.

0 / 23

Easy Modern key

SSH is the front door to every server.

Create an ed25519 key with comment ops@build.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Fingerprint

SSH is the front door to every server.

Show the fingerprint of ~/.ssh/gitlab_key.pub.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Install key

SSH is the front door to every server.

Install ~/.ssh/gitlab_key.pub for user deploy on 10.0.8.8.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Fix key permission

SSH is the front door to every server.

Make ~/.ssh/gitlab_key readable only by you.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Other port

SSH is the front door to every server.

SSH to admin@gw.example.org on port 2200.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Drop one key

SSH is the front door to every server.

Remove only ~/.ssh/gitlab_key from the agent.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Copy a folder down

SSH is the front door to every server.

Copy folder /etc/nginx from host web2 to the current folder.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Upload a file

SSH is the front door to every server.

Copy invoice.pdf to /tmp/ on 10.0.4.7 as user meera with scp.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Download a file

SSH is the front door to every server.

Copy /var/log/app.log from 10.0.4.7 (user meera) to the current folder with scp.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Named key file

SSH is the front door to every server.

Create an ed25519 key in file ~/.ssh/gitlab_key.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium One remote command

SSH is the front door to every server.

Run free -h on host app-50 over SSH without opening a shell.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Remove host key

SSH is the front door to every server.

Remove the old known_hosts entry for 10.0.8.8.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Final settings

SSH is the front door to every server.

Show the merged settings ssh will use for host app-50.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Agent with lifetime

SSH is the front door to every server.

Add ~/.ssh/gitlab_key to the agent for 2 hours.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Through a bastion

SSH is the front door to every server.

Reach admin@10.0.9.12 through jump host admin@jump.example.org.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium scp on port

SSH is the front door to every server.

Copy notes.txt to gw home folder on port 2200 with scp.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium rsync with exclude

SSH is the front door to every server.

Archive-copy ./photos/ to nas:/backup/photos/ but skip the tmp folder.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium scp with a key

SSH is the front door to every server.

Copy build.zip to the home of ec2-user@3.6.9.12 using the key ~/.ssh/ops.pem.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Hard Local tunnel

SSH is the front door to every server.

Forward local port 13306 to mysql.internal:3306 through host gw, no shell.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Hard SOCKS proxy

SSH is the front door to every server.

Open a SOCKS proxy on local port 1081 through host gw, no shell.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Hard rsync dry run

SSH is the front door to every server.

Preview mirroring ./dist/ to web2:/srv/app/ with delete, archive, verbose.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Hard Server to server

SSH is the front door to every server.

Copy /srv/dump.sql from host app1 to /srv/ on host app2, with the data going through your machine.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Hard Folder on a port

SSH is the front door to every server.

Copy the folder site to /var/www/ on host gw as user deploy, SSH port 2222.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

In short

  1. ssh-keygen -t ed25519 makes keys; protect with 600 and a passphrase.
  2. ssh-copy-id installs keys.
  3. ~/.ssh/config saves hosts, users, keys, jumps.
  4. ssh-agent holds unlocked keys.
  5. -J for jump hosts; -L, -R, -D for tunnels.
  6. scp simple, rsync smart, sftp interactive.

Revision, comparison and interview cards

Revise this lesson in a few minutes. Save the cards on your phone or download them as PNG files. The QR code on each card opens this lesson.

SSH keys in 4 steps. No passwords. ssh-keygen -t ed25519. ssh-copy-id to the server. Then log in.
Revision card: SSH keys in 4 steps · Download PNG · Open card page
~/.ssh/config. Short names for hosts. Host, HostName, User, IdentityFile. ProxyJump for a bastion. Just type the name.
Revision card: ~/.ssh/config · Download PNG · Open card page
scp vs rsync. Copies all files every time. / Sends only changes.
Comparison: scp vs rsync · Download PNG · Open card page
ssh -L vs ssh -R. Local port reaches remote target. / Remote port reaches you.
Comparison: ssh -L vs ssh -R · Download PNG · Open card page
Permission denied (publickey)?. Check key and user. Check .ssh 700, keys 600. Debug.
Interview card: Permission denied (publickey)? · Download PNG · Open card page
Agent forwarding risk?. Root on the jump host can use your agent. Prefer ProxyJump. Jump.
Interview card: Agent forwarding risk? · Download PNG · Open card page
-L vs -R?. -L: local port to remote target. -R: remote port back to you. Local tunnel.
Interview card: -L vs -R? · Download PNG · Open card page
scp vs rsync?. scp copies everything. rsync sends only changes. Mirror.
Interview card: scp vs rsync? · Download PNG · Open card page

More cards: Ravi Sir's Cards.