Skip to content

Instantly share code, notes, and snippets.

Last active February 2, 2022 10:31
What would you like to do?
Add Unix user with only SSH key (without password)
# License: CC0
# Author: Valerio Bozzolan
# Quickly create an user without password but with an SSH key
if [ -z "$KEY" ]; then
echo "Usage: "
echo " $0 'USERNAME' 'SSH-KEY... comment'"
exit 1
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