OpenSSH Passwordless Authentication: Difference between revisions

From UNIX Systems Administration
Jump to navigation Jump to search
No edit summary
No edit summary
Line 2: Line 2:
== Method 1 ==
== Method 1 ==
# Create a public and private RSA key pair.
# Create a public and private RSA key pair.
## <tt>'''$ ssh-keygen -t rsa'''</tt>
#: <tt>'''$ ssh-keygen -t rsa'''</tt>
## Follow the prompts to generate and save the RSA key.
## Follow the prompts to generate and save the RSA key.
# Transfer the public key to the target host.
# Transfer the public key to the target host.
## <tt>'''$ ssh-copy-id <username>@<hostname>'''</tt>
#: <tt>'''$ ssh-copy-id <username>@<hostname>'''</tt>
## Follow the prompt to enter your password.
## Follow the prompt to enter your password.
# Test the passwordless authentication.
# Test the passwordless authentication.
## <tt>'''$ ssh <username>@<hostname>'''</tt>
#: <tt>'''$ ssh <username>@<hostname>'''</tt>


== Method 2 ==
== Method 2 ==

Revision as of 21:10, 13 December 2017

Method 1

  1. Create a public and private RSA key pair.
    $ ssh-keygen -t rsa
    1. Follow the prompts to generate and save the RSA key.
  2. Transfer the public key to the target host.
    $ ssh-copy-id <username>@<hostname>
    1. Follow the prompt to enter your password.
  3. Test the passwordless authentication.
    $ ssh <username>@<hostname>

Method 2

  1. Create a public and private RSA key pair.
    1. $ ssh-keygen -t rsa
  2. Create the .ssh directory and set the permissions on the target host.
    1. Logon to the target host via ssh.
    2. $ mkdir .ssh
    3. $ chmod 700 .ssh
    4. $ touch .ssh/authorized_keys
    5. $ chmod 600 .ssh/authorized_keys
  3. Transfer the public key to the target host.
    1. $ cat .ssh/id_rsa.pub | ssh <username>@<hostname> 'cat >> .ssh/authorized_keys'
    2. Follow the prompt to enter your password.
  4. Test the passwordless authentication.
    1. $ ssh <username>@<hostname>