1

Problem:

I'm trying to disable SSH password auth for multiple servers. Which means I have to modify the sshd_config file. From

#PasswordAuthentication yes

to

PasswordAuthentication no

I really don't wanna do it one by one. Is there any ways that I can distribute/modify the config file on multiple servers with a single command?

Assumptions you can make:

  • Those servers have same OS
  • I can broadcast the SSH command to multiple servers at once

Other notes:

I set the config file to listen different address and/or port on each server.

So this could not be done by downloading the updated config file from a central server.

I prefer a text replacement command to do the job

  • 1
    Given the additional constraint, the answer would very likely depend on whether you can ssh into different servers as root, or if it's possible to run sudo without password to obtain root privilege. – Abel Cheung Jul 10 '15 at 12:01
  • yes, I can ssh all those servers as root, and broadcast the command – Shiji.J Jul 10 '15 at 12:02
  • Super lazy For SERVER in $(cat servers.txt);do scp sshd_conf root@$SERVER:/etc/ssh/sshd_conf;done – TheFiddlerWins Jul 10 '15 at 20:55
9

Look into configuration management tools like Puppet, Ansible or cfengine. They are helpful in the long run.

For a one-off, you could use Augeas, that make this change extremly easy, or even sed, which is present on most systems without further installs.

sed -i s/\#PasswordAuthentication\ yes/PasswordAuthentication\ no/ /etc/ssh/sshd_config

This can be sent in a simple ssh command:

ssh user@server sed ......
  • 1
    Nicer than my comment – TheFiddlerWins Jul 10 '15 at 20:56
  • 1
    And, in order to do it faster, install pssh (= parallell ssh) and use it to run the command - it'll give you nice output on where it worked and where it failed. – Jenny D says Reinstate Monica Jul 11 '15 at 10:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.