Created
June 26, 2018 17:52
-
-
Save sudocurse/8f3bf3a21304e33e0b5ebf60b1980286 to your computer and use it in GitHub Desktop.
make a user, give them key access
This file contains hidden or 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 | |
# consume the first argument so we can deal with the key as one variable | |
username=$1 | |
shift | |
sudo useradd $username | |
sudo -u $username mkdir /home/$username/.ssh/ | |
sudo -u $username touch /home/$username/.ssh/authorized_keys | |
sudo chmod 640 /home/$username/.ssh/authorized_keys | |
# $@ means 'all of the arguments'. since we consumed the first one, all that's left is this. | |
# this approach lets us avoid worrying about whether or not the pubkey was quoted | |
sudo -u $username sh -c "echo $@ >> /home/$username/.ssh/authorized_keys" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment