HTML5: Best viewed in Mozilla Firefox.

This page will be moved to a new location: DCIUX

Header image

RPIsPLC.

Setup SSH.

Setup/use SSH on a Raspberry PI.

Secure Shell (SSH).

Last modified: De Coninck Ivo

Secure Shell (SSH) is a UNIX-based command interface and protocol for securely getting access to a remote computer.
Setting up passwordless logins with SSH.
The example below shows how to use ssh-keygen to generate a key pair.

Setup OpenSSH.

Last modified:

Login to Raspberry Pi.
sudo ssh pi@192.168.1.102
Check if ssh is installed on Raspberry Pi.
pi@raspberrypi ~ $ ps aux | grep ssh
root 2007 0.0 0.2 6212 1064 ? Ss 09:19 0:00 /usr/sbin/sshd
root 2043 0.0 0.7 9804 3188 ? Ss 09:43 0:00 sshd: pi [priv]
pi 2121 0.0 0.3 9804 1520 ? S 09:44 0:00 sshd: pi@pts/0
pi 2173 0.0 0.1 3548 864 pts/0 S+ 11:21 0:00 grep --color=auto ssh

If not installed:
pi@raspberrypi ~ $ apt-get update
pi@raspberrypi ~ $ apt-get install openssh-server
Create a key pair:
pi@raspberrypi ~ $ ssh-keygen -t rsa
And press Enter 3x.

terminal.ssh.keygen.png
Fig1. - SSH kreate key pair.

The keys are stored in the hidden .ssh/ directory in your home directory. ssh-keygen generate a private and an public key.
Change directory permissions if needed.
Change to directory
pi@raspberrypi ~ $ cd .ssh
ls - list directory contents.
pi@raspberrypi ~/.ssh $ ls -ah -l
If needed chmod: Changes the permissions of a file.
chmod 700 ~/.ssh

terminal.check.keygen.png
Fig2. - Check permissions.

On the local Linux (Ubuntu) machine, if needed:
First install OpenSSH.
ivo@aspireI7:~$ apt-get update
ivo@aspireI7:~$ apt-get install openssh-server
Create a key pair:
ivo@aspireI7:~$ ssh-keygen -t rsa
The keys are stored in the hidden .ssh/ directory in your home directory. ssh-keygen generate a private and an public key.
Change directory permissions if needed.
ivo@aspireI7:~$ sudo chmod 700 ~/.ssh
Copy the public key to the Raspberrry Pi board.
ivo@aspireI7:~$ sudo scp ~/.ssh/id_rsa.pub pi@192.168.1.222:~/.ssh/authorized_keys
Login into the Raspberry Pi board and change file permissions if needed.
ivo@aspireI7:~$ sudo ssh pi@192.168.1.222
Password:
ivo@aspireI7:~$ chmod 0600 ~/.ssh/authorized_keys
Logout.
ivo@aspireI7:~$ logout
Now use ssh to connect password-less to the Raspberry Pi!
ivo@aspireI7:~$ ssh pi@192.168.1.222

terminal.ssh.passwordless.png
Fig3. - Now use ssh to connect password-less!

< Previous - - - Next >

Top

Leave a Message.