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

Logged on as bryan@localserver, I'm trying to perform a backup using rsync on a remote host bryan@remoteserver.

I need the rsync connection to elevate privileges on the remote host using --rsync-path='sudo rsync', but I'm having problems, so have decided to simplify matters and just try to get the following working first:

bryan@localserver # ssh bryan@remoteserver 'sudo /usr/bin/whoami'

Once, I've cracked this, I should be able to get rsync working.


What I've done so far:

I've got ssh configured so that bryan@localserver can ssh to bryan@remoteserver using key instead of a password.

bryan@localserver # ssh bryan@remoteserver
bryan@remoteserver #

I've also configured bryan@remoteserver to be able to run /usr/bin/whoami as sudo, without a password in the sudoers file on remoteserver:

bryan   ALL=(ALL) NOPASSWD: /usr/bin/whoami

This works fine:

bryan@remotehost # sudo whoami
root

But from the local server:

bryan@localhost # ssh bryan@remoteserver 'sudo /usr/bin/whoami'
sudo: no tty present and no askpass program specified
Sorry, try again.
sudo: no tty present and no askpass program specified
Sorry, try again.
sudo: no tty present and no askpass program specified
Sorry, try again.
sudo: 3 incorrect password attempts

My complete sudoers file (minus the comments and blank lines) is below:

Defaults env_reset
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
Defaults !requiretty
root    ALL=(ALL:ALL) ALL
bryan   ALL=(ALL) NOPASSWD: /usr/bin/whoami
%admin  ALL=(ALL) ALL
%sudo   ALL=(ALL:ALL) ALL

ssh -t from localserver solves the 'no tty present' error, but still prompts me for bryan@remotehost's password.

Can anyone please explain what the problem is?

localserver is Ubuntu 10.04 x64, remoteserver is Ubuntu 12.04 x64.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Are you a member of the sudo group or admin group? From the sudoers man page:

When multiple entries match for a user, they are applied in order. Where there are multiple matches, the last match is used (which is not necessarily the most specific match).

You can move your bryan ALL=(ALL) NOPASSWD: /usr/bin/whoami line to the bottom so it is the last match. This should keep you from being prompted for a password.

share|improve this answer
    
Perfect, thanks! –  Bryan Sep 14 '12 at 10:32

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.