This article on SSH private key based authentication for SUSE Linux explains how to create a SSH key in a windows machine and use it in a SLES or any Linux machine for authentication.
Create SSH private key in a windows machine
The first step is to install SSH. This can be done either by installing OpenSSH from Github or it can be installed as a part of git. The easiest option is to install as a part of git if you are using Git for source control. The Git installer can be downloaded from here and while installing, ensure that unix commands are selected as a part of installation. Refer the below image for more details.
On successful installation, execute the command “
ssh-keygen” in console. This would create the ssh key pair and public key inside the folder “
C:\Users\[user name]\.ssh“. You can also provide a “passphrase” for additional security.
Configure Target Machine
To enable ssh authentication, we have to add the public key that is generated in above step, to the target machine. To perform this action,login into target SUSE Linux server and create a folder named
Inside this folder, create a file named “
authorized_keys” and copy the contents of the file “
C:\Users\[user name]\.ssh\id_rsa.pub” and paste it to that file. Additional keys can be added to this file as separate lines, if you prefer to login from different machine.
To connect from the machine where the key is created, execute the below line (replace with your respective values) from console.
ssh firstname.lastname@example.org -i "C:\Users\admin\.ssh\id_rsa"
This would allow you to connect to the server without having to provide password.
Alternative option with Putty
The alternative approach is to create public and private key with putty, which doesn’t require separate download and installation of openSSH. Follow the below steps to create key and connect with putty.
1. Download the full putty package from here
2. Extract the zip file and open “puttygen.exe”
3. Click “Generate” button to create a new public and private key.
4. Save the public key and private key by clicking “Save public key” and “Save private key” buttons.
5. Copy the content of public key and paste it into “authorized_keys” file in target SLES server.
The generated public key would be in multiple lines. This has to be concatenated into single line prefixed with “ssh-rsa” before moving it to target machine as the target machine treats each and every line as different keys.
Original Public Key
Formatted SSH Key
6. Close “Putty Key Generator” and open “putty.exe” and provide the basic info and click “save”
7. Expand “SSH” section under “Category” and click “Auth”. In the right hand side pane, browse and select the ssh private key (.ppk) file generated in step 4. Switch back to “Session” section and click “Save” button to persist the changes.
8. Click the “Open” button to create a SSH session with the target server.
9. Accept the security warning to connect to the server