close
close

first Drop

Com TW NOw News 2024

Passwordless SSH login to VPS server with Windows
news

Passwordless SSH login to VPS server with Windows

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

Image description

1. Generate an 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 the need for a password.
bashing
ssh-keygen -t rsa -b 4096 -C "[email protected]"

Explanation:
-t rsa: Specifies what type of key to create, in this case RSA.
-b 4096: The key size in bits (4096 is a strong key size).
-C “[email protected]”: Adds a comment to the key, usually your e-mail.
Output: This command generates two files:
id_rsa: Your private key (keep this safe and do not share it).
id_rsa.pub: Your public key (this will be copied to the VPS server).

2. Check if the SSH key has been created
Verify that your SSH key was successfully created by navigating to the .ssh folder on your local computer.
Location:
plain textC:\Users\tarik\.ssh

Expected files: Search for the file id_rsa.pub. If it exists, your key has been successfully created.

3. Log in to your VPS server
Use the following command to log into your VPS server. This first login will still require your password.
bashing
ssh root@your_vps_ip

Note: Replace your_vps_ip with the actual IP address of your VPS server.
First time logging in:
You may be asked to verify the server fingerprint. Type yes to continue.
Enter your VPS password when prompted.

4. Check or create the .ssh folder on the VPS
Once you have logged in, check if the .ssh folder exists on your VPS server.
Check for .ssh folder:

ls -a

Explanation: This command will display all files, including hidden files (files that start with a period, such as .ssh).
Or use:
ls -ld ~/.ssh

Output if .ssh exists:
plain text
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 necessary): If the .ssh directory does not exist, create it with the following command:
mkdir -p ~/.ssh

Set the correct permissions:
chmod 700 ~/.ssh

Explanation:
mkdir -p ~/.ssh: Creates the .ssh directory, including any necessary parent directories.
chmod 700 ~/.ssh: This sets the permissions on the directory so that 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 enables passwordless authentication.
Command:
scp C:\Users\tarik\.ssh\id_rsa.pub [email protected]:/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.
[email protected]:/root/.ssh/authorized_keys: The destination path on your VPS server.
Please note: You will be asked for your VPS password one more time.

6. Login without password
You should now be able to log into your VPS server without having to enter a password.
Command:
ssh [email protected]

If everything is set up correctly, you will be logged in without having to enter a password.