Created
May 11, 2014 12:13
-
-
Save sharifsalah/ca43ab329b1b3ac60911 to your computer and use it in GitHub Desktop.
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 | |
# enables PasswordAuthentication | |
# creates a user | |
# You can query a metadata server only from its associated instance. | |
# You cannot query an instance's metadata from another instance or | |
# directly from your local computer. | |
# For example, you would send a curl or wget command from the | |
# instance to its metadata server. | |
# see https://developers.google.com/compute/docs/metadata | |
USER=$(curl "http://metadata/computeMetadata/v1/instance/attributes/user" -H "Metadata-Flavor: Google") | |
PASS=$(curl "http://metadata/computeMetadata/v1/instance/attributes/pass" -H "Metadata-Flavor: Google") | |
CONFIG=/etc/ssh/sshd_config | |
/bin/cp -p $CONFIG $CONFIG.orig && | |
/usr/bin/awk ' | |
$1=="PasswordAuthentication" {$2="yes"} | |
{print} | |
' $CONFIG.orig > $CONFIG | |
/etc/init.d/ssh restart | |
/usr/sbin/useradd -s /bin/bash -m -d /home/$USER $USER | |
echo $USER:$PASS | /usr/sbin/chpasswd | |
/usr/bin/passwd -e $USER |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's a command to create the instance in such a way that it uses this startup script:
(don't forget to substitute values where marked)