[Windows/Mac/Linux] Password-less SSH Access and Hints

To access SSH without entering password every time.
You can generate a public/private key pair, and authorize the public key on remote server.
Essential if your need to run automated scripts.
Works on Linux / Mac / Windows (Under bash)
(For Windows + PuTTY, check the tutorial here)

  1. Prepare public/private on your LOCAL machine
    Run ssh-keygen under bash (Press ENTER 3 times without entering passphrase)
    Your you get your public key is under ~/.ssh/id_rsa.pub, and private key under ~/.ssh/id_rsa
  2. SSH to REMOTE machine with password
    On the REMOTE account you want to have access to, sudo -i  if your want to authorize root
    mkdir ~/.ssh/
    vim ~/.ssh/authorized_key
    Paste the content of ~/.ssh/id_rsa.pub on your LOCAL machine.
  3. Disconnect from your REMOTE machine, and try to ssh again.
    No password will be prompted if key is installed correctly.

 

Hints 1: ssh / rsync… etc command automatically pickup private key in ~/.ssh/id_rsa
If you have multiple key pair, you can specify it with ssh 1.2.3.4 -i ~/.ssh/id_rsa_other,
or set it permanently by ~/.ssh/config, follow tutorial here

Hints 2: If you connect to remote user name different than your local user name,
Instead of ssh [email protected] every time, you can edit ~/.ssh/config and add config just like previous hint.
So you can simplify your command from ssh [email protected] -i ~/.ssh/id_rsa_other to ssh 1.2.3.4

Host 1.2.3.4
  User root
  IdentityFile ~/.ssh/id_rsa_other

 

One Reply to “[Windows/Mac/Linux] Password-less SSH Access and Hints”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.