Keychain

Raspberry Pi configuration guide to use SSH Key authentication with the RaspController application

The Raspcontroller app has a keychain that will contain all the keys generated through the application itself or through the Raspberry Pi ssh-keygen command.

It is possible to access the keychain directly through the application settings, or when configuring / modifying a new device.

 

RaspController keychain

Android

RaspController - Keychain

iOS

How to generate SSH keys with RaspController

Press the “+” button on the keychain to add a new key.

Now, using the “Generate” tab, enter the name of the key (optional, but useful for recognizing the key when there are many), select the type of key ED25519 (recommended), ECDSA or RSA and its size, finally enter a passphare for encrypt the key (optional, but recommended to protect the key).

At this point it is possible to generate the key pair (public and private). The private key will be used by RaspController, while the public key will need to be copied to the Raspberry Pi.

 

There are three ways to get the public key onto your Raspberry Pi:

– Send public key to Raspberry Pi: appends the key to the ~/.ssh/authorized_keys file of a Raspberry Pi already in your device list, one you can already connect to some other way (with a password, for example). This is the quickest option, since it requires
no manual work on the Raspberry Pi. Keys that are already authorized are left untouched, and the key will only be valid for the user that device logs in with.

– Export public key to file: saves the key as a .pub file on your phone or tablet, to be copied to the Raspberry Pi manually (you need to authorize the key on the server).

– Share public key: opens the Android or iOS share sheet to send the key wherever you need it: e-mail, cloud storage, another computer (you need to authorize the key on the server).

RaspController - Generate key pair
RaspController - Export public key

Android

RaspController - Generate key pair
RaspController - Export SSH key

iOS

How to generate SSH keys with Raspberry Pi

To generate new Ed25519 SSH key type the following command in the Raspberry PI terminal:

ssh-keygen -t ed25519

confirms the name of the file with ENTER and enter a passphrase (recommended).

 

For RSA keys type:

ssh-keygen -t rsa

 

For ECDSA keys type:

ssh-keygen -t ecdsa

 

After generating the key pair, continue with configuring the SSH client.

 

Installing the public key on the server

Create the .ssh folder in your home directory, if it isn’t there already. The -p option prevents an error in case the folder already exists.
mkdir -p ~/.ssh

Make the folder readable and writable only by your user.
This is mandatory: if other users can write to it, SSH ignores the keys it contains as a security measure and access still won’t work.
chmod 700 ~/.ssh

Add your public key line (key_name.pub) to the list of keys authorized to log in as this user.
WARNING: >> appends to the end of the file. With a single > you would erase all the keys already authorized, replacing them with this one.
cat ~/key_name.pub >> ~/.ssh/authorized_keys

Make the list readable and writable only by your user.
As with the folder, without this permission SSH discards the keys.
chmod 600 ~/.ssh/authorized_keys

The key is available immediately.

Old method (deprecated)

 

Edit the ‘sshd_config’ file:
sudo nano /etc/ssh/sshd_config

edit the ‘AuthorizedKeysFile’ line, removing the # symbol (if present) and adding:
.ssh/key_name.pub

Save the file’s contents by pressing CTRL + X (to exit nano), answer “Yes” to the save prompt, then confirm with ENTER.

Now restart the ssh service or reboot the Raspberry Pi:>
sudo /etc/init.d/ssh restart

Use the key on RaspController

When configuring a device, you can use the password or private key for authentication.

To associate a private key to the device, press the button with the key icon, the keychain will be shown. It is possible to select an existing key, generate a new key pair or import a key generated via the Raspberry Pi.

 

Remember to also enter the sudo password, which is required to install the packages needed by RaspController.

 

RaspController - Device configuration

Android

RaspController - Device configuration

iOS

How to import SSH keys generated with Raspberry Pi

In the keychain press the “+” key to add a new key then select the “Import” tab.

Enter the name of the key (optional but useful for identifying it).

It is possible to import the private key by selecting a file or it is possible to paste the contents of the key by making a long tap on the text box and selecting “Paste” in the displayed menu.

If you wish, you can also import the public key (optional, not necessary for correct operation).

Finally enter the passphrase used to encrypt the key (leave blank if no passphrase was used).

After saving, the key is added to the keychain. Now you can pair it with a device.

RaspController - Import SSH key

Android

RaspController - Add SSH Key

iOS

For a user added manually later

Remove the password prompt from this user.

Create a custom sudoers file using (replace bob with your user):

sudo visudo -f /etc/sudoers.d/010_bob-nopasswd

Insert the following contents on a single line:

bob ALL=(ALL) NOPASSWD: ALL

Save the file and exit.

Only for root user

Keyed root access is allowed by the default OpenSSH configuration (“PermitRootLogin prohibit-password”), with “PermitRootLogin no” in sshd_config the procedure fails.