👋 Errors, improvements or other cool stuff? Let me know! 😀
mkdir ~/.ssh
chmod 700 ~/.ssh
Path: ~/.ssh/config
# /!\ Use `~`, `$HOME` doesn't work.
# macOS Sierra 10.12.2 or later:
# Automatically load keys into the ssh-agent and store passphrases in your keychain.
AddKeysToAgent yes
UseKeychain yes
# Default identity.
IdentityFile ~/.ssh/KEYNAME
# My server
Host my-shortcut example.com 123.123.123.123
HostName example.com
User foo
IdentityFile ~/.ssh/foo@example
# Git repo
Host github
HostName github.com
User git
IdentityFile ~/.ssh/me@github
keyname=$(echo "`whoami`@`hostname`" | cut -d'.' -f 1)
ssh-keygen -b 4096 -f ~/.ssh/$keyname -C $keyname -N ""
ssh-add ~/.ssh/$keyname
Option 1:
ssh-copy-id [email protected]
Option 2:
cat ~/.ssh/${keyname}.pub | ssh [email protected] \
"mkdir ~/.ssh && chmod 700 ~/.ssh && touch ~/.ssh/authorized_keys && \
chmod 600 ~/.ssh/authorized_keys && cat >> ~/.ssh/authorized_keys"
Option 3:
Copy public key to clipboard
pbcopy < ~/.ssh/${keyname}.pub
diff local-file.txt <(ssh user@remote "cat remote-file.txt")
diff <(ssh user@remote1 "cat remote-file.txt") <(ssh user@remote2 "cat remote-file.txt")