One Word to Connect: ~/.ssh/config
EasyLinux Fundamentals10-15 minYou've been typing ssh -p 2222 root@localhost like a tourist. Time to move in.
~/.ssh/config teaches your SSH CLIENT a per-host recipe, so user + host + port collapse into one word that every SSH tool understands — ssh, scp, sftp, rsync, all of them.
1. Create /root/.ssh/config describing the labbox:
Host labbox
HostName localhost
Port 2222
User root
(Your key auth is already set up, and a config file should be private: chmod 600 it.)
2. Check your work without connecting: ssh -G labbox prints the settings the client resolved — you should see hostname localhost, port 2222, user root in the output.
3. Use the alias for real: ssh labbox 'echo $SSH_CONNECTION > /root/proof/alias-landed.txt' — no -p, no user@, no host. One word.
4. And it works for scp too — no capital -P needed, the port lives in the config now: scp labbox:/srv/warehouse/secret-recipe.txt /root/inbox/
- Write a /root/.ssh/config Host block: labbox → localhost, port 2222, user root
- Verify the alias resolves with ssh -G labbox
- Connect by alias and leave the receipt at /root/proof/alias-landed.txt
- Fetch /srv/warehouse/secret-recipe.txt into /root/inbox/ using scp with the alias
Hands-on lab: you work on a real Linux box in your browser, graded on the machine's actual state.
