For the Windows server:
- Open the Remote Desktop Connection (RDP) client and connect to your Windows server.
- Open the 'Microsoft Store' and search for 'Windows Terminal'. Install and open the Windows Terminal as admin.
- In the Windows Terminal, run the following command to open the SSH configuration file:
If the
notepad.exe %UserProfile%\.ssh\authorized_keys.sshfolder doesn't exist, create it first. - Copy the contents of your Linux client's
id_rsa.pubfile (the public key) and paste it into theauthorized_keysfile. - Save the
authorized_keysfile and close Notepad.
Now, you should be able to connect to your Windows server using SSH from your Linux client. Here's how:
- In the Linux terminal, run the following command:
Replace
ssh username@windows_server_ipusernamewith the appropriate user account on the Windows server, andwindows_server_ipwith the IP address or hostname of your Windows server. - If you set a passphrase for your SSH key, you will be prompted to enter it. If not, you should be logged in automatically.
That's it! You have now set up SSH access from your Linux client to your Windows server using an SSH key pair. This method is more secure than using a password-based authentication, as it eliminates the need to remember and manage complex passwords.
First, install OpenSSH server inside your Linux Distro:
sudo apt install openssh-server
On the Linux client:
- Open the terminal on your Linux machine.
- Check if you already have an SSH key pair by running the following command:
If you see files named
ls -al ~/.sshid_rsaandid_rsa.pub, you already have a key pair. - If you don't have a key pair, you can generate one by running the following command:
This will create a 4096-bit RSA key pair and associate it with the email address you provided.
ssh-keygen -t rsa -f ~/.ssh/id_rsa - When prompted, choose a location to save the key files and enter a passphrase (optional) or just press ENTER to skip passphrase.
- Your public key (
id_rsa.pub) is now ready to be copied to the Windows server. - cat ~/.ssh/id_rsa.pub
- copy the pub key
- open powershell as admin
- In the Terminal, run the following command to open the SSH configuration file:
If the
notepad.exe %UserProfile%\.ssh\authorized_keys.sshfolder doesn't exist, create it first. - Copy the contents of your Linux client's
id_rsa.pubfile (the public key) and paste it into theauthorized_keysfile. - Save the
authorized_keysfile and close Notepad. - Run the command below. The output shows
Truewhen you're a member of the built-in Administrators group.
(New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)-
If the output shows
Trueyou are an admin user. Copy the public key to administrators_authorized_keys:cp %UserProfile%\.ssh\authorized_keys "$env:programdata\ssh\administrators_authorized_keys"or
cp $env:USERPROFILE\.ssh\authorized_keys "$env:programdata\ssh\administrators_authorized_keys"_Please note administrators_authorized_keys is the file name without any extension.
`get-acl "$env:programdata\ssh\ssh_host_rsa_key" | set-acl "$env:programdata\ssh\administrators_authorized_keys"`
-
For non-admin users,
copy the public key to authorized_keys file (without any extension).
cp "C:\Users\cloudikeme\Documents\pub_key.txt" $env:USERPROFILE\.ssh\authorized_keysIf you don't have .ssh folder under $env:USERPROFILE folder then manually create it
for Windows client
Here are the steps to create an SSH key pair and set up SSH access on a Windows client and a Linux server:
-
Open PowerShell or Command Prompt as an administrator.
-
Generate an SSH key pair:
ssh-keygen -t rsa -b 4096 -f %USERPROFILE%\.ssh\id_rsa
This will create the private key id_rsa and the public key id_rsa.pub in the %USERPROFILE%\.ssh directory.
- Copy the contents of the public key file
%USERPROFILE%\.ssh\id_rsa.pub.
-
Open a terminal and navigate to the
/home/username/.sshdirectory, whereusernameis the name of the user you want to grant SSH access to. -
If the
.sshdirectory doesn't exist, create it:
mkdir ~/.ssh
- Create or edit the
authorized_keysfile and paste the content of the public key you copied from the Windows client:
nano ~/.ssh/authorized_keys
-
Save the file and exit the text editor.
-
Set the correct permissions for the
.sshdirectory and theauthorized_keysfile:
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
Now, the Linux server is configured to accept SSH connections from the Windows client using the provided SSH key pair.
To connect from the Windows client to the Linux server using the SSH key, use the following command:
ssh -i %USERPROFILE%\.ssh\id_rsa username@linux_server_ip
Replace username with the username on the Linux server and linux_server_ip with the IP address or hostname of the Linux server.
This setup allows you to connect to the Linux server from the Windows client without using a password, as the SSH key is used for authentication.
open powershell as admin ssh-keygen.exe -t rsa -f $env:USERPROFILE.ssh\id_rsa