Connect with SSH to the Raspberry Pi key exchange

If your Raspberry Pi is exposed on the Internet you can disable SSH service which is not always practical or limit connections to those with key exchange. And it is this method that we will see today.

securiser raspberry pi ssh cle

Linux or Mac

  1. If it does not exist, create the .ssh
    mkdir $HOME/.ssh
    chmod 700 $HOME/.ssh
  2. Go to the .ssh
    cd $HOME/.ssh
  3. Generating your keys. The option 4096 increases the security of your key (instead of 2096 by default). Finally when the system will ask you a “passphrase” (a password to secure your private key), although it is not compulsory you suspect it is recommended to use a !
    ssh-keygen -b 4096
    Here you are with a private key (id_rsa) and a public key (
    raspberry pi generate rsa key sshYour private key must be kept in your .ssh directory
    Your public key is that you must put (or cause to) up on servers where you want to connect.


for Windows, you can use PuTTYgen to generate your keys.

Install and authorize your public key

  1. Send your public key to the server. You can use scp, an ftp client, etc. for your file
  2. To connect to the server
  3. Add the file contents you sent in step 1 in the file .ssh/authorized_keys User which want to impersonate
    cat >> $HOME/.ssh/authorized_keys

Disable authentication password

For now allow only users with key, just change the configuration of the SSH service

  1. Add the following line to / etc / ssh / sshd_config
    PasswordAuthentication no
  2. Restart the Service
    service ssh restart


There you are now with a Raspberry Pi a bit more secure !


You may also like...