SSH configuration in Raspberry Pi

Enabling default SSH access

In order to enable SSH access after downloading Raspbian Lite without desktop environment and writhing it to SD card you must add empty file called ‚ssh‚ (no extension) on boot drive while your SD card is still connected to your PC. Next place the SD card in your Raspberry Pi and boot.

Login to Raspberry Pi using SSH connection

In command line type with your Raspberry Pi IP address:

ssh pi@xxx.xxx.xxx.xxx

and provide default password raspberry

Change default password

Change password using this command:

passwd

Configure password less SSH access

First make sure that you have keys generated for your client (PC). If you using Cmder on Windows 10 check following directory for files id_rsa and id_rsa.pub

C:\Users\XXXXX\AppData\Roaming\SPB_16.6\.ssh

Next copy the public key

ssh-copy-id pi@xxx.xxx.xxx.xxx

Disable logging with password

For security reasons it is better to disable asscess with password and use only key dependent authentication, so edit the ssh configuration file:

sudo nano /etc/ssh/sshd_config

Find line

#PasswordAuthentication yes

remove comment (# character) and change value to no

PasswordAuthentication no

Now restart the service or reboot the Raspberry

sudo /etc/init.d/ssh restart
sudo reboot

Changing SSH port

This is an optional step, you can change the default port from 22 to something else by editing SSH config file:

sudo nano /etc/ssh/sshd_config

change the port 22 to something else and restart SSH service as in previos

Port 50022

Next restart the ssh service

sudo service ssh restart

Sources

https://www.raspberrypi.org/documentation/remote-access/ssh/passwordless.md