Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

So I have a script that needs to be executed remotely as root. This isn't a problem with most Linux distros since they have a root account. But since Ubuntu does not, executing anything as root requires a 2-step process of entering the account password twice - once to log in and once for sudo. The SSH process to launch the script is automated, so it cannot pause for user input for the second password request.

Does anyone know, short of hacking Ubuntu to re-enable root (not an option), if unattended SSH script execution with superuser privilege on the target machine is possible? Also, having no experience with Debian, does Debian behave this way too?

share|improve this question
up vote 1 down vote accepted

You can ssh in using key-based only authentication, and then edit the sudoers file not to require a password. This will eliminate the password at the two steps you described.

To see up ssh key based ssh access:

ssh-copy-id dest-server

And the for the sudoers file:

sudo visudo -f /etc/sudoers
#uncomment the following and then add yourself to the sudo group

Better would be to require no password for sudo only for the commands you need to automate this particular function. See my answer here for that.


share|improve this answer

This isn't a problem with most Linux distros since they have a root account. But since Ubuntu does not

Is this a serious sentence? I am yet to see a single *nix system without root account.

sudo su

and you are root. After that use passwd to set root password. And BAM! you are able to login as root (but only if you enable RootLogin in ssh)!

UPDATE: Or use ssh keys as others suggested.

share|improve this answer

By default connecting as the root account is possible. You just need to setup your ssh keys for the root account. Add your public key to /root/.ssh/authorized_keys

Tou could also create a service account to login that has sudo setup with NOPASSWD.

serviceaccount ALL = NOPASSWD: ALL

On Debian by default the root account will have a password assigned during the install. Though if you use the expert mode installer you can choose an option that will disable the root account and setup sudo exactly like Ubuntu. I strongly prefer the disabled root account because we have many admins, and I want people to login as themselves and then use sudo to perform admin tasks so a log of root activities is created.

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.