Last active
February 2, 2022 10:31
-
-
Save valerio-bozzolan/70e0184478fa0ffa52a37745ac04f333 to your computer and use it in GitHub Desktop.
Add Unix user with only SSH key (without password)
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/sh | |
# | |
# License: CC0 | |
# Author: Valerio Bozzolan | |
# https://gist.github.com/valerio-bozzolan/70e0184478fa0ffa52a37745ac04f333 | |
# | |
# Quickly create an user without password but with an SSH key | |
# | |
USERNAME="$1" | |
KEY="$2" | |
if [ -z "$KEY" ]; then | |
echo "Usage: " | |
echo " $0 'USERNAME' 'SSH-KEY... comment'" | |
exit 1 | |
fi | |
adduser "$USERNAME" --disabled-password | |
mkdir --parents /home/"$USERNAME"/.ssh | |
echo "$KEY" >> /home/"$USERNAME"/.ssh/authorized_keys | |
chown "$USERNAME":"$USERNAME" -R /home/"$USERNAME"/.ssh | |
chmod 640 /home/"$USERNAME"/.ssh/authorized_keys | |
chmod 755 /home/"$USERNAME"/.ssh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment