You are going to need this if you want to establish a connection to a Linux server from Windows and you don’t want to write the username, server IP, or password each time to establish the connection.
For this example I’m going to use Windows Terminal, you can download it from the windows store if you don’t have it, but you can use the ssh client that you prefer.

First, open Windows Terminal with the PowerShell console and write the following command


You can leave the option by default pressing enter, this will create a public/private RSA key pair into the default folder C:\Users\<username>/.ssh/

Next, go to the folder C:\Users\<username>/.ssh, open the file with your favorite text editor, and copy all the content of the file.

Connect to the Linux server using the Windows Terminal, to do this you need your username, server IP, and password:

ssh <username>@<server ip>

In the Linux server open the .ssh folder

cd ~/.ssh/

If the folder doesn’t exist you need to create it

Then you need to open or create the file authorized_keys with your favorite text editor, I’m going to use nano:

sudo nano authorized_keys

Paste the content of the copied previously and save the file.

Now you can connect to the Linux server without the password using the command

ssh <username>@<server ip>

Next, we are going to create a Windows environment variable to store the previous command so you don’t need to remember the IP, you can do that in the Windows Terminal with the command

setx <variable name> "<username>@<server ip>"

You can use the same command to update the value of the variable

Finally, to establish the connection with the Linux server you can call the environment variable with the username and server IP:

ssh $env:<variable name>

Tagged in:

, ,