Linux Servers: SSH, Permissions and Logs SSH and Keys Instead of Passwords
1 / 5
Next
SSH and Keys Instead of Passwords ~16min

Connecting

ssh username@203.0.113.10
ssh -p 2222 username@myserver.com

You now have a shell on a machine that may be in another country. Everything you type happens there.

Keys are better than passwords

ssh-keygen -t ed25519 -C "amina@laptop"

This makes a pair: id_ed25519 (PRIVATE, never share, never commit) and id_ed25519.pub (public, safe to hand out).

ssh-copy-id username@myserver.com

That appends your public key to the server's ~/.ssh/authorized_keys. From then on you log in without typing a password, and brute-force attempts against your password become irrelevant.

Harden it

In /etc/ssh/sshd_config:

PasswordAuthentication no
PermitRootLogin no

Then restart the service. Test the key login in a SECOND terminal before closing the first, locking yourself out of a remote server is a genuinely bad afternoon.

Moving files

scp report.pdf user@server:/home/user/
rsync -avz --delete ./site/ user@server:/var/www/site/

rsync only transfers what changed, which is why it beats FTP for deployment. Be careful with --delete: it removes files on the server that are absent locally.

Tasks
Preview