3

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

2
  • 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, 2011 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, 2011 at 14:54

2 Answers 2

4

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.

0

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/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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