Remote Login – SSH

Raspberry Pi can be accessed remotely by Secure Shell (SSH) by default (Default to be off since Sep 2016 release). You can connect your PC to Raspberry Pi via SSH and use the command line just the same way as you’re on the Pi. To use SSH, you need the IP address of the Raspberry Pi (that’s why static IP is recommended), and your username and password, or you can create a certificate later and use it instead of a password.

Other than the IP address, Raspberry Pi can also be connected by hostname. The default hostname is “raspberrypi.local”. If you don’t know the IP address, this is a replacement of it.

The default username is “pi” and the default password is “raspberry”. If you have changed your password on earlier setup (and you should), use your own password.

On Windows, PuTTY is the the most popular client for remote access. It can be downloaded at http://www.putty.org.

Run PuTTY as administrator, select SSH for connection type, enter the IP address and login information, then connect.

On Mac OS, we use terminal to connect to Raspberry Pi. Type in the one of following command:

  • ssh <username>@<IP address>

Then type in your password and get connected.

SSH can also be used to transfer files between Raspberry Pi and your PC. This is called Secure Copy (SCP).

On Windows, you need to download PSCP from PuTTY ebsites . Open Command Line and use the following command:

  • If you want to copy file from your PC to Raspberry Pi:
    • pscp <source files> <username>@<IP address>:<destination path>
  • If you want to copy file from your Raspberry Pi to your PC:
    • pscp <username>@<IP address>:<source files> <destination path>

On Mac OS, scp is integrated in terminal. The command is as following:

  • If you want to copy file from your Mac to Raspberry Pi:
    • scp <source files> <username>@<IP address>:<destination path>
  • If you want to copy file from your Raspberry Pi to your Mac:
    • scp <username>@<IP address>:<source files> <destination path>

We also need to disable root login via SSH, especially if you would like to setup access via internet, as root password cannot be change. This is configured by sshd_config, edit the file with the following command:

  • sudo nano /etc/ssh/sshd_config

Find the following line:

  • PermitRootLogin yes no

Change from yes to no to disable root login. Then save and exit, and restart SSH service:

  • sudo service ssh restart

If you plan to make a headless pi and access via SSH all the time, SSH is off as default from Sep 2016. You may create an empty file named ssh under boot partition to override this setting after install the system to SD card.

With SSH, we no longer need a monitor and a keyboard to access Raspberry Pi. It’s a huge save of money for an extra monitor, Hurray!

 

 

Leave a Reply