Skip to content

Instantly share code, notes, and snippets.

@iampeterbanjo
Last active November 6, 2021 09:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iampeterbanjo/5789f71def0c1754bd510640337755c7 to your computer and use it in GitHub Desktop.
Save iampeterbanjo/5789f71def0c1754bd510640337755c7 to your computer and use it in GitHub Desktop.
Create ssh user
# create new user, user directory and use bash shell
sudo useradd -m $1 -s /bin/bash
# add user to sudo group
usermod -a -G sudo $1
# use root ssh key for this user
mkdir -p /home/$1/.ssh
touch /home/$1/.ssh/authorized_keys
cat ~/.ssh/authorized_keys >> /home/$1/.ssh/authorized_keys
# own user key and set permissions
chmod 700 /home/$1/.ssh
chmod 644 /home/$1/.ssh/authorized_keys
chown -R $1 /home/$1/
# check ssh login allowed
grep PubkeyAuthentication /etc/ssh/sshd_config
# set user password
passwd $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment