Thursday, December 15, 2011

Add a new user to Amazon EC2 instance

After connecting to your Amazon EC2 instance, you can add a new user with sudo privilege with following steps:
  1. Open a putty session, log in with the default user, ec2-user
  2. sudo su
  3. useradd new_user_name
  4. passwd new_user_name, give a password for the new user
  5. vim /etc/sudoers, insert line "new_user_name ALL = NOPASSWD: ALL" at the end of the file
  6. cd /home/new_user_name
  7. mkdir .ssh
  8. cp ../ec2-user/.ssh/authorized_keys .ssh/authorized_keys
  9. chown -R new_user_name:new_user_name .ssh
  10. chmod 700 .ssh
  11. chmod 600 .ssh/*
Open another putty session and log in with the same private key you use for ec2-user.

3 comments:

  1. Hi, can the ftp username be an email address? I'm switching from another webhost and have existing users that use that format.

    ReplyDelete
  2. You should use the 'visudo' command, rather than vim the file directly

    ReplyDelete
  3. Wrong both users have access to each other;s accounts
    ssh-keygen -f newuser_key

    etc

    ReplyDelete