SSH
Table of contents
Generate OpenSSH key in Mac
-
Run
ssh-keygen
, or usingrsa
then run:ssh-keygen -t rsa
- The SSH key file path is under
~/.ssh
directory. - You will be prompt enter passphrase, press enter for empty passphrase
- Upon creation, you will see
id_rsa
andid_rsa.pub
- The SSH key file path is under
-
Run
cd ~/.ssh
, thenls -a
- It outputs 2 files:
id_rsa
andid_rsa.pub
- It outputs 2 files:
-
Adding
id_rsa.pub
value to the VM you want to SSH-ing- Eg: Digital ocean » My profile » Security » Add SSH, paste the value in there.
Remove an old host keys in Mac
- Assume Digital Ocean remote IP is
192.25.25.0
, to remove, run below command.
ssh-keygen -R 192.25.25.0
# old key path: ~/.ssh/known_hosts.old
Define SSH with specific host.
- Under
~/.ssh
directory, openconfig
file
Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/key_name_1
IdentityFile ~/.ssh/key_name_2
SSH working logic for connecting 2 remote hosts
Host A
- Inside Host A
- Create key:
ssh-keygen -t rsa
- Above key will be a pair files:
.rsa
&&.pub
- Copy content from
.pub
Host B
- Inside Host B
- Go to folder
/.ssh
- Adding
authorized_keys
file - Paste the content from
.pub
ofHost A
- Done