cloud

Add Users to Google Compute Engine / EC2 Instances

KeysIn the past, when I wanted to share a Linux box with other users, it was simply by creating another user and making sure their password are ‘strong’. These days, it’s much safer not to use passwords over ssh but rather keys in order to connect (over ssh) to your machines in the cloud.

Here is the full list of commands you need to do in order to add a user. It’s being tested on Ubuntu so if you are on another OS, please continue with caution.


###################################################################################
#
# Add More Users to Google Compute Engine / EC2 Instances
# Author: Ido Green | @greenido
# Date: 21/SEP/2015
#
###################################################################################
# If you wish to use passwords ignore this flag of –disabled-password
sudo adduser newuser-name –disabled-password
sudo su – newuser-name
mkdir .ssh
chmod 700 .ssh
touch .ssh/authorized_keys
# (!) Important – without these exact file permissions, you will not be able to
# log into this account using SSH.
chmod 600 .ssh/authorized_keys
# Edit the authorized_keys file and paste the public key for your key pair
# into the file. It should like:
# ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQClKsfkNkuSevGj3eYhCe53pcjqP3maAhDFcvBS7O6V
# Make sure to copy just the key without any spaces before/after it!
vi .ssh/authorized_keys
# Retrieving the Public Key from your private key file
# If you don't have your publich key (just the file of the private key)
# This is what you need to do in order to extract it:
chmod 400 the-new-key.pem
ssh-keygen -y
# When prompted to enter the file in which the key is, specify
# the path to your .pem file. For example:
/path_to_key_pair/the-new-key.pem
# You will get something like:
# ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQClKsfkNkuSevGj3eYhCe
# 53pcjqP3maAhDFcvBS7O6Vhz2ItxCih+PnDSUaw+WNQn/mZphTk/ab/wB96x
# Make sure to copy it without any spaces before/after
####
#
# Now, hold you finger and try to connect
#
####
ssh -i my_key.pem newuser-name@11.11.11.11
# If things are not going well try:
ssh -v -i my_key.pem newuser-name@11.11.11.11
# You should get the full details why things are not working.
# Another option: tail -f -n 80 /var/log/auth.log on the remote box
# If you wish to remove the user
sudo userdel -r olduser

Misc


Discover more from Ido Green

Subscribe to get the latest posts sent to your email.

Standard

One thought on “Add Users to Google Compute Engine / EC2 Instances

  1. Pingback: History of Harsh Agrawal Famous Blogger in India. - Shuvampost.com

Comments are closed.