Passwordless SSH Login to VPS Server Using Windows

Md.Tarikul - Aug 24 - - Dev Community

This guide will walk you through the steps to set up passwordless SSH login to your VPS server from a Windows machine.

Image description

1. Generate SSH Key on Your Local Machine
Start by creating an SSH key on your local Windows machine. This key will be used to authenticate your login to the VPS server without needing a password.
bash
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

Explanation:
-t rsa: Specifies the type of key to create, RSA in this case.
-b 4096: The key size in bits (4096 is a strong key size).
-C "your_email@example.com": Adds a comment to the key, usually your email.
Output: This command generates two files:
id_rsa: Your private key (keep this secure and do not share it).
id_rsa.pub: Your public key (this will be copied to the VPS server).

2. Verify SSH Key Creation
Check if your SSH key has been created successfully by navigating to the .ssh directory on your local machine.
Location:
plaintextC:\Users\tarik\.ssh

Expected Files: Look for the id_rsa.pub file. If it exists, your key was created successfully.

3. Log In to Your VPS Server
Use the following command to log in to your VPS server. This initial login will still require your password.
bash
ssh root@your_vps_ip

Note: Replace your_vps_ip with the actual IP address of your VPS server.
First-Time Login:
You may be prompted to verify the server’s fingerprint. Type yes to continue.
Enter your VPS password when prompted.

4. Check or Create the .ssh Directory on the VPS
Once logged in, check if the .ssh directory exists on your VPS server.
Check for .ssh Directory:

ls -a

Explanation: This command lists all files, including hidden ones (files beginning with a dot, like .ssh).
Or Use:
ls -ld ~/.ssh

Output if .ssh Exists:
plaintext
drwx------ 2 user user 4096 Aug 24 12:34 /root/.ssh

Output if .ssh Does Not Exist:
ls: cannot access '/root/.ssh': No such file or directory

Create the .ssh Directory (If Needed): If the .ssh directory does not exist, create it with the following command:
mkdir -p ~/.ssh

Set Correct Permissions:
chmod 700 ~/.ssh

Explanation:
mkdir -p ~/.ssh: Creates the .ssh directory, including any necessary parent directories.
chmod 700 ~/.ssh: Sets the directory's permissions so only the owner (you) can read, write, and execute.

5. Copy Your Public Key to the VPS
Now, copy your public key (id_rsa.pub) from your Windows machine to the VPS server. This step allows passwordless authentication.
Command:
scp C:\Users\tarik\.ssh\id_rsa.pub root@74.208.202.89:/root/.ssh/authorized_keys

_Explanation:
_scp: Secure copy command, used to transfer files between hosts.
C:\Users\tarik.ssh\id_rsa.pub: Path to your public key on your local machine.
root@74.208.202.89:/root/.ssh/authorized_keys: The destination path on your VPS server.
Note: You will be prompted for your VPS password one last time.

6. Log In Without a Password
Now, you should be able to log in to your VPS server without entering a password.
Command:
ssh root@74.208.202.89

If everything is set up correctly, you’ll be logged in without needing to enter a password.

. .
Terabox Video Player