Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have ssh RSA key authentication setup between a client and an ubuntu server (following this procedure):
-the RSA key authentication for ssh and rsync work fine (no need for password).
-the RSA key authentication for sudo rsync and sudo ssh fails (I'm prompted for a password).
-I need to use sudo rsync to write the remote files locally.

I'm running the command as follows:

user1@server:/$ sudo su user2
user2@server:/$ rsync # ok
user2@server:/$ sudo rsync # remote host password prompt

FYI both user1 and user2 are part of sudoers

Any idea where that could be coming from?


updated: to clarify, the password prompt is not coming from sudo but from the server

share|improve this question
Are you being asked for a password for sudo or rsync? I suspect sudo (in the absence of other information), which means you would have to add the sudo command with NOPASSWD: to sudoers. – lsd May 11 '11 at 14:53
It looks like an environment issue. Try running su - user The - will cause you to inherit the users environment. Alternatively you could specify the path to the key file : something like rsync -e ssh -i /home/user2/.ssh/private.key – Martin May 11 '11 at 14:54
up vote 4 down vote accepted

You need to tell it to use the correct public key. I suspect ssh is still using user1's key, not user2. Use this command:

sudo -u user2 ssh -i ~user2/.ssh/id_rsa remoteserver

I tested this on my machine and it worked.

share|improve this answer

this problem is in

====at the end of file add this====

this will remove password promt for user1 using sudo command.

dont forget that sudo users may store they ssh keys in /root/.ssh/ and not in /home/user1/.ssh/

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.