Created
August 10, 2016 20:31
-
-
Save gasserk/8f4fff7a851de43bc9dc713597a57add to your computer and use it in GitHub Desktop.
User_data for custom account and ssh key
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
#Replace {{myaccount}} with e.g. your id | |
#TODO: Replace {{myaccount}} with appropriate shell variable and references | |
#This has been tested in RHEL7, AWS-Linux, Ubuntu 14.04 | |
#!/bin/bash -xe | |
cat << EOF > /etc/sudoers.d/{{myaccount}} | |
# User rules for {{myaccount}} | |
{{myaccount}} ALL=(ALL) NOPASSWD:ALL | |
EOF | |
# create user | |
useradd -m -s /bin/bash {{myaccount}} | |
# drop in SSH public authorized key | |
mkdir -p /home/{{myaccount}}/.ssh | |
# sample key - this is the insecure Vagrant key pair from https://github.com/mitchellh/vagrant/tree/master/keys | |
# (save the vagrant private key locally as .pem file to access this instance) | |
echo "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key" > /home/{{myaccount}}/.ssh/authorized_keys | |
chown -R {{myaccount}}:{{myaccount}} /home/{{myaccount}}/.ssh | |
chmod 700 /home/{{myaccount}}/.ssh | |
chmod 600 /home/{{myaccount}}/.ssh/authorized_keys |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment