Last active
November 29, 2020 22:59
-
-
Save joshua-in-boots/b3d8bb5ea6088d6863d2264de00d3bfa to your computer and use it in GitHub Desktop.
VM bootstraping script to replace login account of AWS Ubuntu instance
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/bash | |
# Default login ID of VM Instance. | |
# https://docs.aws.amazon.com/ko_kr/AWSEC2/latest/UserGuide/managing-users.html | |
OLD_ID=ubuntu | |
# Name a new ID at your taste | |
NEW_ID=joshua | |
NEW_HOME=/home/$NEW_ID | |
AUTH_KEY=$USER_HOME/.ssh/authorized_keys | |
useradd -m -d $NEW_HOME -s /bin/bash $NEW_ID | |
usermod -aG adm,dialout,cdrom,floppy,sudo,audio,dip,video,plugdev,netdev,lxd $NEW_ID | |
sudo -u $ID mkdir $NEW_HOME/.ssh | |
sudo -u $ID chmod 750 $NEW_HOME/.ssh | |
cp /home/$OLD_ID/.ssh/authorized_keys $AUTH_KEY | |
chown $NEW_ID:$NEW_ID $AUTH_KEY | |
chmod 600 $AUTH_KEY | |
# /etc/sudoers.d/90-cloud-init-users exists in Ubuntu 20.04 | |
# Check this on the other distros. | |
sed -i "s/$OLD_ID ALL=(ALL) NOPASSWD:ALL/$NEW_ID ALL=(ALL) NOPASSWD:ALL/g" /etc/sudoers.d/90-cloud-init-users |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment