Skip to content

Instantly share code, notes, and snippets.

@mbodo
Last active June 8, 2023 13:25
Show Gist options
  • Select an option

  • Save mbodo/5c900d724652e2e2f48a2baf7e558848 to your computer and use it in GitHub Desktop.

Select an option

Save mbodo/5c900d724652e2e2f48a2baf7e558848 to your computer and use it in GitHub Desktop.
OpenSSH Cheatsheet

SSH RSYNC SSHFS Cheatsheet

SSH

Generate RSA 4096 bit key

ssh-keygen -f ~/.ssh/my_key_rsa -t rsa -b 4096

Check is ssh-agent is running

$ ssh-agent -s
SSH_AUTH_SOCK=/tmp/ssh-kdX73wLO6hbu/agent.18081; export SSH_AUTH_SOCK;
SSH_AGENT_PID=18081; export SSH_AGENT_PID;
echo Agent pid 18081;

Add key to ssh-agent

$ ssh-add ~/.ssh/my_key_rsa
Enter passphrase for /home/myaccount/.ssh/my_key_rsa: 
Identity added: /home/myaccount/.ssh/my_key_rsa (/home/myaccount/.ssh/my_key_rsa)

List ssh-agent keys

$ ssh-add -l
4096 SHA256:souHXiVi1bqgysC1cpsoT/stNwdNiWrnTJrMuTgs6rA /home/myaccount/.ssh/my_key_rsa (RSA)

Copy public key to server

ssh-copy-id -i /home/myaccount/.ssh/my_key_rsa.pub user@host

Add IdentityFile to ~/.ssh/config

Host server1
     HostName server1.mydomain
     User myuser
     IdentityFile ~/.ssh/my_key_rsa

Add Host fingerprint to ~/.ssh/knowing_hosts

ssh-keyscan -H 192.168.X.X >> ~/.ssh/known_hosts

Show the fingerprint of the key file

ssh-keygen -l -f ~/.ssh/id_rsa.pub
2048 2e:8c:fd:aa:9f:95:86:9e:b0:d2:a6:1a:7e:d3:3e:74 .ssh/id_rsa.pub (RSA)

Copy public key to clipboard

tr -d '\n' < ~/.ssh/id_rsa.pub | xsel --clipboard --input

Rsync

Copy single file

rsync -avz --progress <file>.sh <remote_user>@<ip_address>:/<remote_path>

SSHFS

Attach host directory to guest

sshfs -o allow_other some_user@some_ip:/path/host /path/guest

e.g

sshfs -o allow_other foo@10.1.1.1:/home/foo /home/guest/foo

Sources:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment