Shell script to connect to multiple ssh servers

Hello,

I have access to several linux servers (mostly centos based) located in a DC in another country.
from day to day I need to login to each of them to do some work (they dont have gui/window manager installed, I work only from console), or even to just do a check like df -h for disc usage.

I have stored all the ssh passes to a locked file and each time I have to run putty, copy/paste the pass for each server (I have locked root login, you have to authenticate as a user first then run su)etc etc.

My idea is to create a script (that will be localy in a linux vm) that will

1) just do a complete ssh connection to the server just by typing a command for example the server's name "server1"

2)run a command in a server and give me the ouput, like df -h in "server1"

about the 1st , if straight root connection was enabled it would be easy, but I dont know how to do it now that root login is not permited.

What have you done?

I think the first thing you should do is set up key based authentication, so you do not need to enter the password every time you log in to a server. As you are looking for a script solution rather than an alias one, and you want to do several servers at once, key based auth is one of the basic requirements.

Secondly, you need to see if you can set up a (limited) passwordless sudo environment, so you can run certain commands using sudo without being asked for a password.

If you do both of these, you would be able to script what you want to do.

For single commands, it might be worth looking at creating a simple alias though...

Great!! :slight_smile:

I would recommend you to look into commands like rexec/remsh, ssh.

Hope this feeds you :slight_smile: