In this post, I’ll show you how to bypass the password prompt and get you connected to your server immediately after you enter to execute the SSH command.
One of the hassles when connecting to your server is the entering-password step.
Now, you might think – it’s not a big deal, it’s just an extra step – but what if you have a reasonably complex password that you need to retrieve from somewhere else (notes, or password management app). Or your job requires you to access the servers frequently, then skipping small steps like entering passwords can help speed things up big time.
Traditionally, to login to the server, you do these steps in its chronological order:
ssh firstname.lastname@example.org, hit Enter/Return
We’re going to eliminate Step 2; after inserting
ssh email@example.com and hitting Enter/Return, you’re immediately connected to the server. How about that?
And don’t worry, this is extremely secure, as long as you ensure no unauthorized personnel can gain access to your PC.
Let’s get started.
Before we dive into the execution, here is some information about your local machine and remote server you need to collect beforehand.
Write them down in a note, or at least have them accessible at ease.
This is the path to .ssh/ on your machine. It varies from one operating system to another.
For more information on how to find the path to ssh folder in Windows 10, click here.
Note: For macOS users, typing the command
cd ~/.ssh will usually bring you into the .ssh folder.
You need the credentials and several other details about your server. In short, collect the following:
With the information gathered from 1.2, login to your server, and find the path to the “authorized_key” file.
The file is usually located at:
Have you gotten all the required information? Great, let’s proceed!
In order for the password-less SSH login to work, we will need an SSH key from your local computer.
If you’re sure that there are no existing SSH Keys in your local machine, then you can jump right ahead to creating a new SSH Key.
ls -al ~/.ssh.
If the folder contains files like the following, then SSH Keys exist on your local machine.
You can either keep them, provided that you still remember their respective passphrases, else I’d recommend that you delete them.
If the folder is empty, then you’re set to creating your new SSH key.
cd ~/.ssh && ls -aland hit Enter/Return. This will bring you into the SSH folder and list all existing files inside it.
Note: If you’re performing this on a shared workstation or are unsure of which files to delete, do not proceed.
If your SSH folder is empty, then it probably looks something like this.
Let’s start generating a new SSH Key.
ssh-keygen -t rsa -b 4096 -C "firstname.lastname@example.org".
Your SSH Key has been successfully created, and your terminal should output something similar to the screenshot below.
We’ve come to our last and final step – uploading the generated key (public key) to the server.
cd ~/.sshto go inside the .ssh folder.
cat id_rsa.pub | ssh username/domain.com 'cat - >> /path/to/server/.ssh/authorized_keys'.
The command above will copy the public key in id_rsa.pub (from local machine) into authorized_keys (in remote server).
If the command executed correctly, you will be prompted to enter the password to the remote server, insert the password, and hit enter/return.
That’s it! Now, let’s give it a test.
You should be able to login without entering the password.
Note: It’s worth noting that logging in without the password will only apply to the user where our public key is added. Assuming there are several users on our server: root, john and jane. You’ve added your public key to
authorized_keys file that belongs to jane. You will be able to login to the SSH as jane without the password, but when need to login as root or john, you will still need to provide the password.
Copy the following codes, replace “/path/to/.ssh/” with the actual path to your .ssh folder, and hit Enter/Return.
chmod 700 /path/to/.ssh && chmod 600 /path/to/.ssh/*
This will ensure your newly created SSH key be stored securely inside the .ssh folder.