To set up SSH key based authentication from Linux Server B to Server A, follow these steps:
Step 1: Generate SSH Key Pair on Server B
ssh-keygen -t rsa -b 4096 -C “your_email@example.com”
2.When prompted, press Enter to save the keys in the default location (~/.ssh/),
and optionally, set a passphrase.
Step 2: Copy the Public Key to Server A
ssh-copy-id user@server_A_IP
ssh-copy-id user@server_A
2.Verify permissions on Server A:
Ensure that the ~/.ssh directory and authorized_keys file have the correct permissions on Server A:
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
Step 3: Test SSH Key-Based Authentication
ssh user@server_A_IP
ssh user@ServerA
Step 4: (Optional) Disable Password Authentication on Server A
sudo nano /etc/ssh/sshd_config
sudo nano /etc/ssh/sshd_config
ChallengeResponseAuthentication no
PasswordAuthentication no
PasswordAuthentication no
o Save and close the file.
sudo systemctl restart sshd
you can still set up SSH key-based authentication. Here’s how you can do it using tools available on Windows:
Step 1: Generate SSH Key Pair on Windows (Server B)
2.Generate the SSH key pair:
• Open Git Bash on Windows.
• Run the following command to generate an SSH key pair:
ssh-keygen -t rsa -b 4096 -C “your_email@example.com”
ssh-keygen -t rsa -b 4096 -C “your_email@example.com”
• When prompted*, press Enter to save the keys in the default location (/c/Users/YourUsername/.ssh/id_rsa), and optionally, set a passphrase.
Files Involved:
o – C:\Users\YourUsername.ssh\id_rsa (Private Key)
o – C:\Users\YourUsername.ssh\id_rsa.pub (Public Key)
Step 2: Copy the Public Key to Linux Server (Server A)
ssh-copy-id user@ServerA
cat ~/.ssh/id_rsa.pub
2.Copy the key output from the above command.
3.Log in to Server A using PuTTY or another SSH client and open the .ssh/authorized_keys file on Server A:
nano ~/.ssh/authorized_keys
5.Save and close the file.
Files Involved:
• On Server A: ~/.ssh/authorized_keys
Step 3: Test SSH Key-Based Authentication
• You should be able to log in without entering a password, as the key will be used for authentication.
Step 4: (Optional) Disable Password Authentication on Server A
• Set the following parameters:
PasswordAuthentication no
ChallengeResponseAuthentication no
Tools You Might Need on Windows
• Git Bash: Provides a Unix-like terminal on Windows.
Download putty, putty gen, pageant from below link
Step 1: Install PuTTY and Pageant
• Ensure that you have PuTTY and Pageant installed on your Windows machine. Both are available from the PuTTY download page.
Step 2: Convert Private Key to PuTTY Format (if needed)
• If your private key is in OpenSSH format (e.g., id_rsa), you need to convert it to PuTTY’s .ppk format using PuTTYgen.
2.Load your existing private key:
Click on “Load”.
Browse to the location of your private key (id_rsa).
Select the file type as “All Files” to see your key.
Load the key.
3.Save the private key in .ppk format:
Click “Save private key”.
Choose a location to save the .ppk file.
Step 3: Load the Private Key in Pageant
2.Load the private key:
Right-click on the Pageant icon in the system tray.
Select “Add Key”.
Browse to the .ppk file you saved earlier.
Select the file and click “Open”.
If your key is protected with a passphrase, you’ll be prompted to enter it.
Step 4: Use PuTTY with the Loaded Key
2.Configure your session:
In the “Session” section, enter the hostname or IP address of the server you want to connect to.
In the “Connection -> SSH -> Auth” section, ensure “Attempt authentication using Pageant” is checked. This is the default behavior.
Read More Tutorials; Resize Disk Partition in Ubuntu Without LVM