Last active
December 14, 2023 03:37
-
-
Save lorne-luo/804f1d00ebab9d4d6b3aceee1fdae52b to your computer and use it in GitHub Desktop.
setup new user on linux
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
sudo useradd -m lorneluo --shell /bin/bash | |
sudo mkdir -p /home/lorneluo/.ssh | |
sudo touch /home/lorneluo/.ssh/authorized_keys | |
sudo vi /home/lorneluo/.ssh/authorized_keys | |
# past ssh key into /home/lorneluo/.ssh/authorized_keys | |
sudo echo '' >> /home/lorneluo/.ssh/authorized_keys | |
sudo chmod 644 /home/lorneluo/.ssh | |
sudo chmod 600 /home/lorneluo/.ssh/authorized_keys | |
sudo chown -R lorneluo:lorneluo /home/lorneluo | |
sudo gpasswd -a lorneluo wheel | |
sudo usermod -a -G sudo lorneluo | |
sudo echo 'lorneluo ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers.d/10_sudo |
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
template=""" | |
sudo useradd -m {username} --shell /bin/bash | |
sudo mkdir -p /home/{username}/.ssh | |
sudo touch /home/{username}/.ssh/authorized_keys | |
# past ssh key into /home/{username}/.ssh/authorized_keys | |
#sudo echo '' >> /home/{username}/.ssh/authorized_keys | |
sudo chmod 644 /home/{username}/.ssh | |
sudo chmod 600 /home/{username}/.ssh/authorized_keys | |
sudo chown -R {username}:{username} /home/{username} | |
sudo gpasswd -a {username} wheel | |
sudo usermod -a -G sudo {username} | |
sudo echo '{username} ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers.d/10_sudo | |
sudo vi /home/{username}/.ssh/authorized_keys | |
""" | |
print(template.format(username='lorneluo')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment