· Linux, SSH · 1 min read
SSH Key
Generate SSH key and use it to connect to remote server
List SSH key
ls -lah ~/.ssh
cat ~/.ssh/known_hosts
cat ~/.ssh/authorized_keys
Generate SSH key
Command to generate RSA, DSA, ECDSA and Ed25519 key
ssh-keygen -t rsa -b 4096
ssh-keygen -t dsa
ssh-keygen -t ecdsa -b 521
ssh-keygen -t ed25519
NOTE:
- The -t option specifies the type of key to generate.
- The -b option specifies the key size in bits. The default key size is 2048 bits.
- The -C option specifies the comment for the key.
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
Copy SSH key to remote server
ssh-copy-id -i ~/.ssh/id_rsa.pub user@remote_server
Copy SSH key to multiple remote server
ssh-copy-id -i ~/.ssh/id_rsa.pub user1@remote_server1 user2@remote_server2
Open and Copy SSH key to clipboard
# On MacOS
tr -d '\n' < ~/.ssh/id_rsa.pub | pbcopy
cat ~/.ssh/id_rsa.pub | pbcopy
# On Linux
xclip -sel clip < ~/.ssh/id_rsa.pub
# On Windows git bash or WSL
cat ~/.ssh/id_rsa.pub | clip
# Open without copying support all step above
cat ~/.ssh/id_rsa.pub