Skip to content

Instantly share code, notes, and snippets.

@jhordyess
Created March 7, 2022 01:19
Show Gist options
  • Save jhordyess/7bbe1565dc8b82bbf9e13d1f478af95e to your computer and use it in GitHub Desktop.
Save jhordyess/7bbe1565dc8b82bbf9e13d1f478af95e to your computer and use it in GitHub Desktop.
Create a new user and add the SSH public key for Raspberry Pi.
#!/bin/bash
printf "What new username to use? "
read user
printf "Which is the public key? "
read public_key
if [ "$user" != "" -a "$public_key" != "" ]; then
# create user, password required
sudo adduser $user
# add the new user to the gpio group
sudo usermod -a -G gpio $user
echo "Type the password one more time"
# create the .ssh directory and add the public key
su - $user bash -c "mkdir -m 700 ~/.ssh && echo $public_key > ~/.ssh/authorized_keys"
sudo service ssh restart
echo "Done"
else
echo "I need the correct values"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment