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 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 stackoverflow.com Jul 17 '10 at 1:49

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

add comment

2 Answers

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

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
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.