Setting Up SSH Login Without a Password: A Complete Guide

Andy

Administrator
Creative Team
User ID
1
Joined
7 Jan 2019
Messages
1,142
Reaction score
58
Points
48
Effortlessly access your servers with our guide on setting up SSH for seamless, secure connections. Perfect for sysadmins and IT enthusiasts!

Managing multiple servers can often feel like a juggling act. To simplify the process, implementing a password-less SSH login is a smart move. This guide walks you through establishing an RSA key pair for secure, hassle-free connections between two machines, referred to here as machine A (the local machine) and machine B (the remote server).

Understanding the Mechanics of RSA Keys
RSA keys work on a simple principle: machine A encrypts data that only machine B can decrypt. The beauty lies in the security—only machine A knows how to encrypt the messages, and machine B, holding the public key, can decrypt them. This means if someone intercepts the public key, they still can't forge a login to machine B without the private key from A. It's a robust way to ensure that your "password" remains a secret between the two parties involved.

Setting Up Your RSA Keys
  1. Initiate an SSH Connection: Start by logging into machine A via SSH.
  2. Prepare the Environment:
    Bash:
    cd
    mkdir -p .ssh
    cd .ssh
    This ensures you have a dedicated .ssh directory for your keys.
  3. Generate Your Key Pair:
    Bash:
    ssh-keygen -t rsa
    Hit enter three times to accept the default settings and skip the passphrase. Remember, adding a passphrase will require it to be entered each time the key is used which somewhat defeats the purposes for this particular implementation.
  4. Transfer the Public Key: You now have two files in machine A: id_rsa (private key) and id_rsa.pub (public key). Next, add the public key to machine B's authorized_keys:
    Bash:
    scp -C /.ssh/id_rsa.pub [email protected]:/.ssh/authorized_keys
    Replace '[email protected]' with your user and IP details. If there are existing entries in authorized_keys, simply append the contents of id_rsa.pub to it.
  5. Secure Your Private Key:
    Bash:
    chmod 600 id_rsa
    This command restricts access to your private key, a crucial step for maintaining its confidentiality.
  6. Verify the Setup: Test your connection to machine B:
    Bash:
    You should be able to log in without entering a password.

Key Files and Their Roles
  • ~/.ssh/authorized_keys: Located in machine B, it contains the public keys (id_rsa.pub) from one or more machines.
  • ~/.ssh/id_rsa: Your private key is on machine A. Keep this confidential.
  • ~/.ssh/id_rsa.pub: The public key originating from machine A, is to be placed in machine B's authorized_keys.
By following these steps, you'll streamline your server management, making your workflow more efficient and secure. Happy terminaling!
 
 Short URL:
Back
Top