Last active
November 6, 2021 09:13
-
-
Save iampeterbanjo/5789f71def0c1754bd510640337755c7 to your computer and use it in GitHub Desktop.
Create ssh user
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
# 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