Create or migrate user account with SSH login only (no password login) on AWS
EC2 t2.nano with Ubuntu 14.04 LTS.
Create User Account
# login to EC2 running *Ubuntu 14.04*
$ ssh -i my_key.pem ubuntu@my_EC2_IP
# assume the name of the user account is *foo*
$ sudo adduser foo --disabled-password
# su to *foo*
$ sudo su - foo
# Create a *.ssh* directory for the *authorized_keys* file
$ mkdir .ssh
$ chmod 700 .ssh
# Create the public and private keys for ssh login
# Don't use a paraphrase -- just hit enter
$ ssh-keygen -b 1024 -f fookey -t dsa
# After keygen finished,
# two files named *fookey* and *fookey.pub* will be generated.
# *fookey* is private key and *fookey.pub* is public key
$ cat fookey.pub > .ssh/authorized_keys
$ chmod 600 .ssh/authorized_keys
Download fookey to your local machine. Now you can SSH login as foo:
$ ssh -i fookey foo@my_EC2_IP
For more details, see , , and .
Migrate User Account
My case is simple. Every user has his own block device as home directory. So
create user account as described above, mount the user's block device back to
his home directory. Then
$ sudo chown foo:foo /home/foo -R
For more details or more sophisticated case, see and .