Adding Multiple SSH Keys to Your Raspberry Pi

Adding Multiple SSH Keys to Your Raspberry Pi

If you're a Raspberry Pi enthusiast, you know the importance of secure access to your device. Using SSH keys is a secure and convenient way to manage remote access. In this guide, I'll show you how to add multiple SSH keys to your Raspberry Pi, allowing different users or machines to connect securely.

Step 1: Generate SSH Keys

First, you need to generate SSH keys on each client machine that will access your Raspberry Pi. Open a terminal on your client machine and run the following command:

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

Follow the prompts to save the key in the default location (~/.ssh/id_rsa) and optionally add a passphrase for extra security.

Step 2: Copy SSH Keys to Raspberry Pi

Next, you need to copy the SSH key to your Raspberry Pi. The easiest way to do this is by using the ssh-copy-id command. Replace pi@raspberrypi with your actual username and hostname or IP address of your Raspberry Pi:

ssh-copy-id pi@raspberrypi

If ssh-copy-id is not available, you can manually copy the public key. First, display your public key with:

cat ~/.ssh/id_rsa.pub

On your Raspberry Pi, open the authorized_keys file (create it if it doesn’t exist):

ssh pi@raspberrypi
mkdir -p ~/.ssh
nano ~/.ssh/authorized_keys

Paste the public key into this file, then save and exit.

Step 3: Add Multiple SSH Keys

To add multiple SSH keys from different machines or users, repeat the above steps for each key. Each public key should be added as a new line in the ~/.ssh/authorized_keys file on your Raspberry Pi.

Step 4: Verify Permissions

It's crucial to ensure the permissions on the .ssh directory and authorized_keys file are correct to avoid any security issues:

chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

Step 5: Test SSH Access

Finally, test the SSH access from each client machine to make sure the keys are working correctly:

ssh pi@raspberrypi

Example authorized_keys File

Here’s what your ~/.ssh/authorized_keys file might look like after adding multiple keys:

ssh-rsa AAAAB3... user1@example.com
ssh-rsa AAAAB3... user2@example.com
ssh-rsa AAAAB3... user3@example.com

Each line represents a different public key from various clients or users.

Conclusion

By following these steps, you can securely add multiple SSH keys to your Raspberry Pi. This setup allows different machines or users to access your Pi without sharing passwords, enhancing both security and convenience. Enjoy your secure and efficient Raspberry Pi setup!

Comments

Popular posts from this blog

Unsupervised Learning

Automate Blog Post creation using Blogger APIs and Python

Setting up Python Flask server on internet via Port forwarding

Setting up Jupyter Lab integrated with Python, Julia, R on Windows Subsystem for Linux (Ubuntu)

The beginning of Data Quest