SSH & Remote Admin Commands Cheat Sheet
The definitive SSH command reference: Ed25519 key generation, ~/.ssh/config shortcuts, local/remote port tunneling, ProxyJump, and rsync sync with 1-click copy.
Key Generation & Security (4 commands)
ssh-keygen -t ed25519 -C "[email protected]"
Generates modern, high-speed, and secure Ed25519 elliptic-curve SSH key pair.
ssh-keygen -t rsa -b 4096 -C "[email protected]"
Generates a 4096-bit RSA SSH key pair for legacy systems incompatible with Ed25519.
chmod 700 ~/.ssh && chmod 600 ~/.ssh/id_ed25519 ~/.ssh/authorized_keys
Enforces strict POSIX file permissions required by SSH daemon on keys and directory.
ssh-copy-id -i ~/.ssh/id_ed25519.pub user@server_ip
Installs your public key on remote server's authorized_keys file with 1 command.
Connecting & Remote Execution (4 commands)
ssh -i ~/.ssh/custom_key user@server_ip
Connects using an explicit private key identity file.
ssh -p 2222 user@server_ip
Connects to a non-standard SSH port (e.g., 2222 or custom port).
ssh user@server_ip "sudo systemctl restart nginx"
Executes a single command on remote server and immediately returns output locally.
ProxyJump: Connects to internal private subnet host through a public bastion host.
SSH Config File (~/.ssh/config) (2 commands)
Host prod
HostName 198.51.100.10
User ubuntu
Port 22
IdentityFile ~/.ssh/id_ed25519
ServerAliveInterval 60
Configures a named alias in ~/.ssh/config for 1-word login (ssh prod).
Host *
ControlMaster auto
ControlPath ~/.ssh/sockets/%r@%h-%p
ControlPersist 600
Multiplexes SSH connections: reuses existing socket for instant secondary logins.
Port Forwarding & Tunneling (3 commands)
ssh -L 8080:localhost:3000 user@server_ip
Local Port Forwarding: Bridges remote server's internal port 3000 to local localhost:8080.
ssh -R 9000:localhost:8000 user@server_ip
Remote Port Forwarding: Exposes your local port 8000 onto remote server's port 9000.
ssh -D 1080 -N -f user@server_ip
Dynamic Port Forwarding: Spawns a background SOCKS5 proxy server on localhost:1080.
File Transfer (SCP & Rsync) (3 commands)
scp -P 22 -r ./dist user@server_ip:/var/www/html/
Copies local directory recursively to remote path over encrypted SSH.
rsync -avzP --exclude "node_modules" ./ user@server_ip:/var/www/app/
Synchronizes directory over SSH with archive flags, compression, and progress bar.
ssh user@server_ip "tar czf - /var/log" | tar xzf - -C ./backup_logs
Streams compressed directory archive from remote server directly into local folder.
Agent & Troubleshooting (3 commands)
eval "$(ssh-agent -s)" && ssh-add ~/.ssh/id_ed25519
Starts ssh-agent in background and loads private key so you enter passphrase once.
ssh -v -i ~/.ssh/key user@server_ip
Enables verbose debug output: prints key negotiation, cipher suites, and auth failures.
ssh-keygen -R 198.51.100.10
Removes offending host key from ~/.ssh/known_hosts after server rebuild or IP change.