Introduction
- To remotely connect to another computer/server safely.
- Encrypts the connection → nobody can eavesdrop.
- Commonly used to log in to Linux servers from your laptop.
Login
Normal login:
ssh username@server_ip
- Then will be asked for password
- Once connected, can run commands on the VPS as if you were sitting there
SSH Keys (Password-less Login)
Instead of typing password every time, we use SSH keys.
- Generate SSH key on your local machine:
ssh-keygen -t ed25519 -f deploy_key
# ssh-keygen : cmd to generate a new SSH key pair
# -t ed25519 → modern type of SSH key algorithm
# -f deploy_key → custom file name, to save the key in local
- Get two files on local:
- deploy_key → private key, keep secret! 🔒
- deploy_key.pub → public key, share to server 🌐
- Copy public key to VPS:
mkdir -p ~/.ssh
chmod 700 ~/.ssh
nano ~/.ssh/authorized_keys