Link Search Menu Expand Document


Table of contents

Generate OpenSSH key in Mac

  1. Run ssh-keygen, or using rsa 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 and
  2. Run cd ~/.ssh, then ls -a

    • It outputs 2 files: id_rsa and
  3. Adding 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, to remove, run below command.
ssh-keygen -R
   # old key path: ~/.ssh/known_hosts.old

Define SSH with specific host.

  • Under ~/.ssh directory, open config 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

  1. Inside Host A
  2. Create key: ssh-keygen -t rsa
  3. Above key will be a pair files: .rsa && .pub
  4. Copy content from .pub

Host B

  1. Inside Host B
  2. Go to folder /.ssh
  3. Adding authorized_keys file
  4. Paste the content from .pub of Host A
  5. Done