Automatic OpenSSH Login quick guide [Windows to DietPi]

If you want automatic OpenSSH login when opening a terminal to DietPi from windows, I keep this condensed guide in my notes:

Open Powershell and type:

ssh-keygen -t rsa -b 4096

and follow the instructions


In your dietpi terminal, go to your Home directory of user (example: john) by typing:

cd ~

then type the following:

mkdir .ssh
chmod 700 ~/.ssh
touch ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys

Open Powershell and type:

type $env:USERPROFILE\.ssh\id_rsa.pub | ssh 192.168.1.100 "cat >> .ssh/authorized_keys"

Replace 192.168.1.100 with your dietpi address. It will also ask you to login just this once.


Next, we install the SSH Agent on Windows to allow us to autologin. Open Powershell Admin and type:

Get-Service ssh-agent | Set-Service -StartupType Manual

Change Manual to Automatic at your own risk, if you want it to start when Windows boots.

Start the service:

Start-Service ssh-agent

This should return a status of Running:

Get-Service ssh-agent

Now load your key files into ssh-agent (Change John for your windows username):

ssh-add C:\Users\John\.ssh\id_rsa

It should now autologin when opening an SSH session.

It fails for me at
type $env:USERPROFILE.ssh\id_rsa.pub | ssh 192.168.1.100 “cat >> .ssh/authorized_keys”

"type : Der Pfad “C:\Users\XXX.ssh\id_rsa.pub” kann nicht gefunden werden, da er nicht vorhanden ist."
(The path “C:\Users\XXX.ssh\id_rsa.pub” can’t be found, because it is not existing)

at C:\Users\XXX.ssh is only the file known_hosts

personally I added my key’s manually into .ssh/authorized_keys

Ok there is something odd with Powershell.
When I type in the command
ssh-keygen -t rsa -b 4096 I get this output:

Enter file in which to save the key (C:\Users\XXX/.ssh/id_rsa):
So when I just put in a filename it can’t be saved, because of the forward slashes in the default path, Powershell gives me, I guess.
I have to specify a full path, then it can save the keys.

why not using PUTTYgen to generate the keys?

I used now open-ssh and convertet them with putty-gen.
But I used a passphrase for the key, so now it was prompting me for the passphrase everytime, when I was connecting :rofl:

But simple solution (on windows): double click the .ppk file and type in the phrase once, it will be stored and now no passphrase is needed on connection.

To make it even more secure, use OpenSSH server on DietPi and activate 2FA :stuck_out_tongue:

https://ubuntu.com/tutorials/configure-ssh-2fa#1-overview