Created
July 1, 2023 16:42
-
-
Save eswarijayakumar/2dc66ddef4aec95ee4e5961b9b251fce to your computer and use it in GitHub Desktop.
Script to automate Ubuntu User creation with SSH Key access
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 | |
public_key="<provide your public key here>" | |
sudo adduser --disabled-password --gecos "" testuser | |
sudo usermod -aG sudo testuser | |
sudo mkdir -p /home/testuser/.ssh && sudo touch /home/testuser/.ssh/authorized_keys | |
sudo chmod 700 /home/testuser/.ssh && sudo chmod 600 /home/testuser/.ssh/authorized_keys | |
sudo chown -R testuser /home/testuser/.ssh | |
sudo sh -c "echo $public_key > /home/testuser/.ssh/authorized_keys" | |
sudo sh -c "echo 'testuser ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/testuser-user" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment