Connecting to Your Server After Losing SSH Keys: A Beginner-Friendly Guide
Have you ever been locked out of your own server? Don't worry, it happens to the best of us! This guide will help you regain access using SSH keys, even if you've lost your original keys. I will also cover how to use these keys with apps like FileZilla (a FTP) and PuTTY (a SSH client).
What You'll Learn
Creating a new set of SSH keys
Adding your new key to your server
Using your new key with FileZilla and PuTTY
Solving common problems
Step 1: Making Your New SSH Keys
Open your computer's command line:
On Windows: Search for "Git Bash" and open it
On Mac or Linux: Open the "Terminal" app
Type this command and press Enter:
ssh-keygen -t rsa -b 4096
When asked where to save the key, just press Enter to use the default location.
You'll be asked for a passphrase. You can leave this blank for now by pressing Enter twice.
Great job! You now have two new files:
id_rsa
: Your private key (keep this secret!)id_rsa.pub
: Your public key (this one's okay to share)
Step 2: Telling Your Server About Your New Key
Now we need to let your server know about your new key:
Log into your server using the DigitalOcean console (or whatever method you still have access to).
Once you're in, type this command and press Enter:
nano ~/.ssh/authorized_keys
You'll see a text editor. Go to the end of any text already there.
Now, open the
id_rsa.pub
file on your computer (remember, that's your public key). Copy all of its contents.Go back to your server and paste the copied text at the end of the file. Make sure it's on a new line!
Exit from the editor.
You've now added your new key to your server!
Step 3: Using Your New Key with FileZilla and PuTTY
For FileZilla:
Open FileZilla
Go to File > Site Manager
Click "New Site" and give it a name
Fill in these details:
Host: Your server's IP address
Port: 22
Protocol: SFTP - SSH File Transfer Protocol
Logon Type: Key file
User: Your username on the server (often "root")
Key File: Click Browse and find your
id_rsa
file
For PuTTY:
PuTTY needs a special key format. Here's how to get it:
Download and open PuTTYgen
Click "Load" and find your
id_rsa
fileClick "Save private key" and save it as a
.ppk
fileIn PuTTY, go to Connection > SSH > Auth
Browse and select your new
.ppk
file
Step 4: Troubleshooting
If things aren't working:
Double-check that you're using the correct username and server address.
Make sure you selected SFTP (not FTP) in FileZilla.
If you're on Mac or Linux, try this command to fix permissions:
chmod 600 ~/.ssh/id_rsa
Look for error messages in FileZilla's log (at the top of the window) for clues.
You Did It!
Congratulations! You should now be able to connect to your server using your new SSH key. Remember to keep your private key safe and never share it with anyone.
If you're still having trouble, don't hesitate to ask for help from your hosting provider or a tech-savvy friend. Good luck and happy server managing!
Subscribe to my newsletter
Read articles from Zainul Khan directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by