Hi there, In this article, I’ll show you How to Generate SSH Keys with PuttyGen and login into CentOS from the Windows machine.
SSH is the most common remote login method because It’s very secure. If you’re trying to login via ssh, every time It requests username & password. This is a bit annoying to many system administrators and the Public & Private key system is the solution for this situation. The following steps are described in this article.
- Download Putty & PuttyGen
- Generate Private & Public Keys
- Save Public Key in the CentOS machine
- SSH to CentOS from Windows Machine
1. Download Putty & PuttyGen
PuttyGen is the most popular software for generating Public & Private keys for ssh authentication. Use the following link to download It.
Download 32bit or 64bit version according to your OS.
Also Download Putty client for start the ssh session.
2. Generate Private & Public Keys
After download & Installation of PuttyGen, you can easily generate SSH keys. Open the PuttyGen and click the “Generate” button.
Now move the cursor on empty space for generate the key files.
Click the “Save Public Key” button to save the generated public key file. Do the same for private key file.
After generating keys, copy the public key appears on puttygen.
3. Save Public Key in the CentOS machine
We already generated private key & public key files via PuttyGen and also copied the public key to the clipboard. Now we have to create a file in CentOS and save the public key in it. SSH uses the authorized_keys file to find ssh public keys in the system. Therefore need to copy the public key into the authorized_keys file.
By default the authorized_keys file is not created with centOS installation. Normally this file located in .ssh directory in users home directory. Therefore we also need to create that directory. Use the following commands.
chmod 700 ~/.ssh
In this case I used vim editor, but you can also use nano editor. Now copy the public key from clipboard and save the authorized_keys file.
Now restart the sshd service using following command.
systemctl restart sshd
4. SSH to CentOS from Windows Machine
Now we have configured everything for public key authentication with SSH. The final step is select the appropriate private key file from putty and log into centOS machine.
Click the “Browse” button & select private key file. This file must be related to copied public key file into centOS machine.
Add the “Auto Login Username”. This prevents type username for login shell.
Now navigate to session section, enter the IP address of the centOS machine and click “Open” button to login via SSH.
If you correctly follow the above steps, the following terminal window will appear. Note the root is already logged into the system using ssh keys.
That’s all about Generating public and private keys and login into centOS machine with ssh. If you have any questions, leave a comment below.