How to Connect To Linux (CentOs 7) Using SSH Keys (Password free authentication) from Windows
Enjoying this content? Subscribe to the Channel!
Secure & Passwordless: SSH Key Authentication from Windows to CentOS 7 using PuTTY
Hello tech fans and welcome back to Darren’s Tech Tutorials!
If you work with Linux servers frequently, you know that constantly typing your password can slow down your workflow. The solution? SSH Key Authentication! Not only does this method provide a streamlined, passwordless login experience, but it also significantly enhances your server’s security profile.
In this guide, we’re going to walk you through the entire process of setting up public/private SSH key pairs using PuTTY on Windows and configuring your CentOS 7 server to accept this highly secure form of authentication.
Let’s dive in and secure your server access!
1. Getting Started: Installing PuTTY and Verifying Connectivity
Before we generate keys, we need to ensure you have the necessary tools and that your server is reachable.
Step 1: Download PuTTY
PuTTY is a free, open-source SSH client essential for this tutorial.
- Download PuTTY and PuTTYgen directly from the official source:
www.putty.org - Select the appropriate installer for your system (we recommend the 64-bit version).
- Run the installer and complete the setup.
Step 2: Test Initial Connection
It’s always a good practice to confirm your standard password-based connection works before making configuration changes.
- Open PuTTY.
- Enter your server’s IP address (e.g.,
192.168.1.133) in the Host Name (or IP address) field. - Navigate to Connection > Data and enter your desired auto-login username (e.g.,
Darren). - Return to the Session page, name your session (e.g.,
My Server), and click Save. - Click Open. You should be prompted for your password. Log in successfully, then type
exitto close the connection.
2. Generating Your Public and Private Key Pair
Now we will use PuTTYgen to create the cryptographic key pair.
Step 1: Open PuTTYgen
- Open PuTTYgen (the PuTTY Key Generator).
- Ensure the key type at the bottom is set to RSA.
- Click the Generate button.
- Move your mouse randomly over the blank grey area. This movement generates entropy (randomness) to create a highly secure key.
Step 2: Save Your Keys Securely
Once the keys are generated:
- Skip Passphrase (Optional but Recommended for Passwordless Login): For truly passwordless entry, we will not set a key passphrase. If you wish to add an extra layer of security, you may set a passphrase now.
- Click Save public key and save it to a secure location (e.g., a dedicated
Keysfolder). Name it something likemy_public_key.pub. - Click Save private key. PuTTYgen will warn you about not having a passphrase; click Yes to continue. Name it something like
my_private_key.ppk.
Important: The private key (
.ppkfile) is your digital identity for the server. Treat it like a password!
Step 3: Copy the Public Key Text
The public key needs to be uploaded to your CentOS server.
- In the PuTTYgen window, highlight and copy the entire block of text under the heading: “Public key for pasting into OpenSSH authorized_keys file.”
3. Configuring the CentOS 7 Server
With the public key copied, we now need to log into the server normally one last time to configure the SSH directory structure and upload the key.
Step 1: Create the SSH Directory and Set Permissions
Log back into your server using PuTTY with your standard username and password. Execute the following commands, one by one:
# 1. Create the .ssh directory in your home folder
sudo mkdir ~/.ssh
# 2. Set strict permissions (rwx for owner only)
sudo chmod 700 ~/.ssh
Step 2: Create the Authorized Keys File
We will use the vi editor to create the authorized_keys file and paste in the copied public key.
# 3. Open the authorized_keys file for editing
sudo vi ~/.ssh/authorized_keys
- Press
ito enter INSERT mode in Vi. - Right-click (or use Ctrl+V/Shift+Insert depending on your PuTTY settings) to paste the entire public key string you copied from PuTTYgen.
- Press the
Esckey to exit INSERT mode. - Type
:wqand press Enter to Write and Quit the file.
Step 3: Correct Ownership and Permissions
Proper ownership and restrictive permissions are essential for SSH to trust the key file.
Remember: Replace
YourUserNamewith your actual Linux username (e.g.,Darren).
# 4. Set ownership recursively on the .ssh directory
sudo chown YourUserName:YourUserName ~/.ssh -R
# 5. Set strict permissions for the keys file (read/write for owner only)
sudo chmod 600 ~/.ssh/authorized_keys
Step 4: Restart the SSH Service
To ensure the server recognizes the changes immediately, restart the SSH daemon:
sudo service sshd restart
Type exit to close the PuTTY connection.
4. Finalizing PuTTY for Passwordless Login
The final step is to configure your saved PuTTY session to use the private key you generated earlier.
- Open PuTTY.
- Click on your saved session profile (
My Server) and click Load. - In the category tree on the left, navigate to Connection > SSH > Auth.
- Click Browse next to the “Private key file for authentication” field.
- Locate and select the private key file you saved (
my_private_key.ppk). - Scroll back up to the Session category at the top of the tree.
- Click the Save button to store this key path within your profile.
Test the Connection
Now, click Open to connect to your server.
If everything is configured correctly, you will see a message confirming authentication via the public key, and you will be brought straight into the command line without ever being prompted for a password!
Conclusion
Congratulations! You’ve successfully configured secure, passwordless SSH key authentication from your Windows machine to your CentOS 7 server. This setup is not only convenient, but it also vastly improves your security posture by eliminating the risk associated with simple password attacks.
If you enjoyed this tutorial and found the steps helpful, please be sure to Like and Subscribe to Darren’s Tech Tutorials for more clear, accessible technology guides. If you ran into any issues or have questions about SSH keys, drop a comment below—I’m happy to help!
Thanks for tuning in, and happy networking!