Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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 192.168.1.2:... # ok
user2@server:/$ sudo rsync 192.168.1.2:... # remote host password prompt

FYI both user1 and user2 are part of sudoers

Any idea where that could be coming from?

Thanks.

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
2  
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
add comment

2 Answers

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
add comment

this problem is in

#/etc/sudoers
====at the end of file add this====
user1 ALL = NOPASSWD:ALL

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
add comment

Your Answer

 
discard

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.