I just created a new instance with Ubuntu (natty) AMI. After logging in with ssh -i key.pem ubuntu@ip
user, I did sudo adduser timmy
and added timmy to admin, sudo adduser timmy admin
. But when I try to login with username ssh -i key.pem timmy@ip
it reutrns: Permission denied (publickey).
3 Answers
To add timmy to the admin group:
usermod -a -G admin timmy
(The -a flag will keep timmy in any secondary groups that he's already in.)
You should set a password for timmy:
passwd timmy
Make sure you can log in with passwords. Edit /etc/ssh/sshd_config
and check that the following line is present:
PasswordAuthentication yes
(If not change it and run /etc/init.d/ssh reload
You can change it [back] to PasswordAuthentication no
once you get this working.)
And if you want to use that key to log in as timmy (in addition to logging in as ubuntu), you need to copy the public key to timmy's account your local machine (assuming you are on a linux machine):
ssh-copy-id -i key.pem timmy@ip
The fist time, you'll have to enter timmy's password.
EDIT:
"I did cp /home/ubuntu/.ssh/authorized_keys /home/timmy/.ssh/authorized_keys"
Make sure permissions are correct on /home/timmy/.ssh
chmod -R 600 /home/timmy/.ssh
chown -R timmy /home/timmy/.ssh
-
When I do
sudo /etc/init.d/ssh reload
I getRather than invoking init scripts through /etc/init.d, use the service(8) utility, e.g. service ssh reload Since the script you are attempting to invoke has been converted to an Upstart job, you may also use the reload(8) utility, e.g. reload ssh
– TimmySep 6, 2011 at 22:23 -
-
Thanks,
PasswordAuthentication yes
helped. But, if I change it tono
, the problem exists. Is it okay to keep it on?– TimmySep 6, 2011 at 22:32 -
Yes, however if you do, you should use something like denyhosts because your sever will be probed by bots. But if you cannot log in with
PasswordAuthentication no
, then you didn't get the keys working right. Are you prompted for a password if you dossh -i key.pem timmy@ip
?– xoferSep 6, 2011 at 22:43
Copy the ~/.ssh/authorized_keys
for the user ubuntu over to timmy. Either that or a safer option would be to create a new ssh key pair for timmy.
-
I did
cp /home/ubuntu/.ssh/authorized_keys /home/timmy/.ssh/authorized_keys
but it still returns that error– TimmySep 6, 2011 at 22:18 -
Check the permission on
timmy/.ssh/authorized_keys
. It should be 600. If you want to generate a new key just follow the link above. Sep 6, 2011 at 22:21 -
You must place the public portion of the key in $HOME/.ssh/authorized_keys
. Also, you may want to create a new key set for this user (with ssh-keygen
)