My cheat sheet of ssh and scp one-liners.
# Generate a new key
- Follow the prompts to setup desired key-type and key location.
ssh-keygen
# Copy specific key to remote server
ssh-copy-id -i ~/.ssh/id_rsa.pub user@server.com
Or, copy with non-default port…
ssh-copy-id -i ~/.ssh/id_rsa.pub -p 1234 user@server.com
If using a non-standard named key
SSH auto-loads only standard names by default. Add the following to ~/.ssh/config to ensure that connections can be made without a password.
Host server
HostName server.com
User bob
IdentityFile ~/.ssh/id_bobby
IdentitiesOnly yes
Further reading for SSH passwordless login.1
# Remove a key from known_hosts
ssh-keygen -f '~/.ssh/known_hosts' -R '192.168.0.187'
SCP
# Transfer files to remote
scp -P 1234 "file.txt" user@192.168.1.20:/var/www/html/dir
Or, transfer files with non-default port…
scp -P 1234 "file.txt" user@192.168.1.20:/var/www/html/dir
# Transfer files from remote to local
scp user@192.168.1.20:/var/www/html/dir/file.txt /home/user/Documents
# Transfer local to local
scp archive.tar.gz 192.168.1.10:/home/user/Documents
-
Setup SSH Passwordless Login: Setup SSH Passwordless Login ↩
»
Visitors: Loading...
