Creating a new user:
1. Create a new user using the following command:
Sudo adduser newuser
2. Switch to the new user context:
Sudo su – newuser
3. Create a .ssh directory for the authorized_keys file. Authorized keys is where you store the custom public key to be generated in later steps for user access.
4. Change the file permissions of the .ssh directory to 700 (this means only the file owner can read, write, or open the directory):
Chmod 700 .ssh
5. Create a file named “authorized_keys” in the “.ssh” directory:
6. Change the file permissions of the authorized_keys file to 600 (this means only the file owner can read or write to the file).
Chmod 600 .ssh/authorized_keys
Creating the custom SSH key for the user created above:
1. Under the ec2-user context, generate the public and private keys using the following command:
Sudo ssh-keygen -f newuser
2. Enter empty passphrases and let the key generation continue.
3. In the same directory, 2 files (newuser and newuser.pub) are created.
4. Use the following command to open the private key newuser:
Sudo vi newuser
5. Copy the contents of this file to a text editor and save it as a .pem file (This will serve as your private key).
6. Use the following command to open the public key newuser.pub:
Sudo vi newuser.pub
7. Copy the contents of this public key to clipboard.
8. Change user context to newuser using the following command:
Sudo su – newuser
9. Add contents of the public key to the authorized_keys file by pasting clipboard contents after opening the file using the following command:
Sudo vi .ssh/authorized_keys
10. Once done, you should be able to login as the new user using the following SSH command from a Linux machine:
Ssh -I newuser.pem newuser@DNSName
Some useful links:
Managing users: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/managing-users.html
Using VI editor: http://www.howtogeek.com/102468/a-beginners-guide-to-editing-text-files-…
Connecting to your Linux EC2 instance: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-connect-to-instan…