1

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

jag7720
  • 41
  • 2

2 Answers2

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

  • 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 03:00
1

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.

Jeremy M
  • 819
  • 4
  • 10