1

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 3

2

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
4
  • When I do sudo /etc/init.d/ssh reload I get Rather 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
    – Timmy
    Sep 6, 2011 at 22:23
  • Ok, use service ssh reload or reload ssh
    – xofer
    Sep 6, 2011 at 22:25
  • Thanks, PasswordAuthentication yes helped. But, if I change it to no, the problem exists. Is it okay to keep it on?
    – Timmy
    Sep 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 do ssh -i key.pem timmy@ip?
    – xofer
    Sep 6, 2011 at 22:43
0

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.

3
  • I did cp /home/ubuntu/.ssh/authorized_keys /home/timmy/.ssh/authorized_keys but it still returns that error
    – Timmy
    Sep 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.
    – arunkumar
    Sep 6, 2011 at 22:21
  • Thank you! It works. I had to chmod 600
    – Timmy
    Sep 6, 2011 at 22:26
0

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)

1
  • /home/.ssh: No such file or directory
    – Timmy
    Sep 6, 2011 at 22:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .