I'm new to here and want to raise an interesting question about mass remote configuration of Linux servers.

Imagine you get a list of IP addresses for 100 servers with a fresh install of Ubuntu, publicly accessible over the Internet, an ssh key already in authorized_keys, and a sudo password for each server. Describe how you would provision those servers and install OpenVPN.

Puppet wasn't installed on those new servers, just got SSHD enabled.

  • 1
    What do you mean "in max 150 words"? Why would we have a word limit? Don't expect us to just do your homework for you. What do you have so far? Which part of this is confusing you? – terdon Mar 27 '16 at 13:26
  • The "In max 150 words," makes this sound a lot like homework or a pre-interview test. Why would we help you with either? – Henrik supports the community Mar 27 '16 at 13:28
  • Sorry to make you annoying, its a local group discussion from my region and im not the writer of question. – Nonstop Mar 27 '16 at 13:29
  • Henrik, just leave it if you feel not comfortable of my question, thank you! – Nonstop Mar 27 '16 at 13:33
  • OK, so what do you have so far? Please have a look at our help center, especially the section on "How to ask a good question". We expect users here to at least try before asking. So, please edit your question and show us what you have so far and what part of this is giving you trouble. For example, do you know the command needed to install OpenVPN? – terdon Mar 27 '16 at 13:37

The simplest approach is to have a list with the server name/IP and the sudo password:

server1 pass1
server2 pass2
server3 pass3
server100 pass100

Then, you can iterate over that file, reading the server and password into variables and using ssh to run the remote command on the server:

while read server pass; do 
    ssh  "$server" sudo -S apt-get install network-manager-openvpn <<<"$pass"
done < file

The -S option of sudo lets you pass the password from standard input:

 -S, --stdin
             Write the prompt to the standard error and read the password
             from the standard input instead of using the terminal device.
             The password must be followed by a newline character.

The <<< is a bash (and a few other shells) trick called a here string.


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.