How to Access <put name here> via ssh, even more relaxed

  • Hi.

    The config-file still doesn't satisfy you? Ok, here's the solution for really lazy people: Generate a pair of keys and let the computers deal with them.


    In the Windows powershell from the link above, cd into the .ssh directory and have Windows generate public keys for authentication:

    cd C:\Users\<username>\.ssh

    Replace <username> with your user name , then type

    Code
    ssh-keygen -t rsa

    to generate the keys.

    When prompted for the filename, passphrase and repeat passphrase, just hit ENTER to confirm.

    This stores 2 encrypted files on your computer, one to be used localy, the other one to be transfered to the remote machine.

    To transfer the file to the remote machine, copy and paste or enter this line, including the word "type":

    Code
    type $env:USERPROFILE\.ssh\id_rsa.pub | ssh pi@192.168.0.39 "mkdir .ssh/ && cat >> ./ssh/authorized_keys"

    all in a single line.

    Replace pi@192.168.0.39 with your data.

    This creates the directory .ssh and a file named authorized_keys , then copies the content of the key-file to your remote machine. You will be prompted for the password. If you get an error: mkdir: cannot create directory '.ssh/' File exists , omit mkdir .ssh/ &&

    That's it. Next time you log on, you just need to type ssh pi@192.168.0.39 or ssh raspi , if you have created a config-file.

    Client and server handle authorization automagic.



    You can do the same from linux to linux, just the routine to copy the keys is a bit smarter: The command is

    ssh-copy-id -i ~/.ssh/id_rsa.pub user@server


    You can copy the keys to multiple machines, not only one.

    73, Martin


    Edit: This generates a key with a length of 2048 (3072) bit. For safety reasons, you should generate a key with 4096 or more bit.

    So call ssh-keygen like this:  ssh-keygen -t rsa -b 4096  (or 8192)