Configure SSH Passwordless Login from Windows to Linux
Setting up SSH passwordless login allows you to connect from your Windows machine to a Linux server securely without typing your password every time. This is particularly useful for automation, scripting, or regular remote management tasks.
Step 1: Check and Install OpenSSH Client
-
Open PowerShell with administrative privileges:
- Press Win + S, type
PowerShell
, right-click on Windows PowerShell, and select Run as Administrator.
- Press Win + S, type
Check if OpenSSH Client is installed:
Get-WindowsCapability -Online | Where-Object Name -like '*OpenSSH.Client*'
If it shows State : NotPresent
, install it:
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0
Step 2: Generate an SSH Key Pair on Windows
- Open Command Prompt or PowerShell. Both tools can execute the
ssh-keygen
command; choose the one you're more comfortable with or have easy access to. - Run the SSH key generation command:
ssh-keygen -t rsa -b 4096
This command generates a secure 4096-bit RSA key, which is recommended for modern usage due to its robust security against brute-force attacks.
-
When prompted:
- Save the key to the default location (e.g.,
C:\Users\YourUsername\.ssh\id_rsa
) by pressing Enter. - Leave the passphrase empty for passwordless login (press Enter twice).
- Save the key to the default location (e.g.,
Example output:
Generating public/private rsa key pair.
Enter file in which to save the key (C:\Users\YourUsername\.ssh\id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in C:\Users\YourUsername\.ssh\id_rsa
Your public key has been saved in C:\Users\YourUsername\.ssh\id_rsa.pub
Step 3: Copy the SSH Public Key to the Linux Server
To enable passwordless login, your public key must be on the Linux server.
- Use the following command in PowerShell to append the public key directly to the
authorized_keys
file on the Linux server:
type $env:USERPROFILE\.ssh\id_rsa.pub | ssh username@hostname-or-ip "mkdir -p .ssh && chmod 700 .ssh && cat >> .ssh/authorized_keys && chmod 600 .ssh/authorized_keys"
Replace:
-
username
with your Linux username. -
hostname-or-ip
with the IP address or hostname of your Linux server.
- Ensure the correct permissions for the
.ssh
directory andauthorized_keys
file are applied as part of the above command.
Step 4: Test the Passwordless SSH Connection
From your Windows machine, test the connection:
- Open Command Prompt or PowerShell.
- Run the SSH command:
ssh username@hostname-or-ip
You should log in without being prompted for a password.
Troubleshooting
If the connection still prompts for a password:
- Verify the SSH key is correctly copied to the Linux server:
cat ~/.ssh/authorized_keys
Ensure it contains the public key from your Windows machine.
-
Check SSH server permissions and configuration:
- Ensure
~/.ssh
has700
permissions andauthorized_keys
has600
. - Restart the SSH service on Linux:
sudo systemctl restart sshd
- Ensure
-
Check firewall or network configurations:
- Ensure port 22 (the default SSH port) is open on the Linux server.
- Verify there are no IP-based restrictions preventing your connection.
- For cloud environments, confirm that the security group or network rules allow SSH access.
Enable debugging during SSH login:
ssh -vvv username@hostname-or-ip
Analyze the output for errors.
Conclusion
Configuring SSH passwordless login from Windows to Linux improves efficiency and security for remote connections. By setting up SSH keys, you eliminate the need for passwords while maintaining secure access. This setup is particularly useful for frequent logins, automated scripts, and system management.
Feel free to leave a comment if you encounter any issues or have tips to share! 😊
Top comments (0)