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 need a way to log into a list of hostname/IPs as a user, su to root and then create/append root's .bashrc

root doesn't have permission to ssh directly into the server

share|improve this question

migrated from Jul 17 '10 at 1:49

This question came from our site for professional and enthusiast programmers.

ssh hostname "sudo -S sh -c 'echo stuff >> /root/foo.txt'" < password.txt

You'll still need to type in each ssh password, but it will read the sudo password from password.txt.

Hope this helps.

share|improve this answer
To add to this, if you're going to ssh to each system anyways, think about copying over a public key. Better security if you also disable password authentication, and with an ssh agent running there's no need to type a password for every system in the future. – Jeremy M Jul 17 '10 at 3:00

As mentioned in godswearhats' comment, sudo -S will probably be useful. Hopefully you have ssh public keys already in place to remove the ssh login prompts. If not I'd recommend pushing them over before the commands. Same number of credential prompts (one for each machine initially, none on the actual change commands), and you're set for no prompts at that level next time.

I'd recommend strongly considering setting up something like Puppet. Like ssh keys, onfiguring that may have the same amount of pain as the actual config push, you can then do the config push with little additional work, and you're set for next time.

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.