Created
March 7, 2022 01:19
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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