I recently migrated to a new VPS server and needed to import a public key for my backup service so that I wouldn’t have to hand out a username/password combination. It had been a while since I’d used SSH for anything and didn’t feel like taking the time to learn everything from scratch again, so I figured I’d just import the keys using the file manager instead. After some trial and error, I finally figured out how to do it without SSH. Here are the steps!
Why You Might Need to Import a Public Key
In my case, I wanted to give my backup service – DropMySite – SSH access to the server so that they could go in and take daily backups. Now obviously I don’t want to give DropMySite my username/password. I could create a new SSH user with the appropriate permissions and let DropMySite log in with a username and password, but that would involve a lot of hassle. I would prefer to keep things simple.
Luckily, DropMySite has a public SSH key that they make freely available to everyone. I just need to import this into my server in a specific location. And when DropMySite tries to connect, my server will allow them to enter without a password because it can see that their public key is installed. Very useful!
Let’s get to it.
Step 1: Find out What Your User’s “Home” Directory is
For me, this was the biggest sticking point, and I didn’t understand why it wasn’t working. I was using the wrong home directory! Every user has a distinct “home” directory path, and you need to know what it is. Often, it’s “/home/[username]”. For root, it’s just “/”. This tutorial is about not using SSH, but if you were to use SSH, you could just type:
And you’ll find out what your home directory is.
One way to know your home directory is to log into your dashboard’s file manager. By default, it should drop you into your “home” directory. So you can just start working from there.
Step 2: Change the Preferences to Allow you to See Hidden Files
By default, both cPanel and InterWorx file managers don’t allow you to see hidden files and folders starting with a “.”. So first go into your file manager preferences and turn on the option allowing you to see hidden files and directories.
Step 3: Create the “.ssh” Folder in the “Home” Directory with the Right Permissions
You should be in your “home” directory by default (hopefully). So create a new folder called “.ssh” – making sure to include the dot (.). Now use the file manager interface to assign it the following permissions:
If you can’t find the option to change the directory permissions, look to the right-hand side. You might see a series of letters. Clicking that will allow you to input the appropriate permissions as shown in this screenshot:
Now that you’ve created the .ssh directory, let’s create a file inside it.
Step 4: Create the “authorized_keys” File Inside the “.ssh” Directory with 0600 Permissions
Next, enter the .ssh folder you just created, and make a new, blank file called “authorized_keys”. Ensure that it has the file permissions of:
As shown here:
Once done, it’s time for the final step.
Step 5: Paste the Public Key into authorized_keys
Now open the “authorized_keys” file that you just created in the text editor that your file manager provides. Open the public key file in your possession and copy everything in it. Then paste it all into a single line in the “authorized_keys” file.
Save your changes, and you’re done.
Congratulations! You’ve successfully managed to import an SSH public key file without using SSH. It’s not something many people do. But if you’re not ready to deal with the terminal just yet, this is an easy way to accomplish the same thing.
I’m a NameHero team member, and an expert on WordPress and web hosting. I’ve been in this industry since 2008. I’ve also developed apps on Android and have written extensive tutorials on managing Linux servers. You can contact me on my website WP-Tweaks.com!
Leave a Reply