2

I have implemented a small beowulf cluster for testing purpose, all nodes with Ubuntu server 18.04.

I have installed pdsh for running the same command on ssh at the same time on multiple node. ssh login is granted passwordless with public/private key distribution over the nodes (example: https://www.rittmanmead.com/blog/2014/12/linux-cluster-sysadmin-ssh-keys/) .

If I try a simple command like "date" , all is fine:

me@master:~$ pdsh -w me@node[0-3] date
node0: Mon Mar 9 18:56:04 UTC 2020
node2: Mon Mar 9 17:26:15 UTC 2020
node3: Mon Mar 9 16:42:37 UTC 2020
node1: Mon Mar 9 17:42:52 UTC 2020
me@master:~$

But if I try a command that require a sudoer privileges like this:

me@master:~$ pdsh -w me@node[0-3] apt update

then it returns these errors:

node0: WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
node0:
node0: Reading package lists...
node0: E: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied)
node0: E: Unable to lock directory /var/lib/apt/lists/
node0: W: Problem unlinking the file /var/cache/apt/pkgcache.bin - RemoveCaches (13: Permission denied)
node0: W: Problem unlinking the file /var/cache/apt/srcpkgcache.bin - RemoveCaches (13: Permission denied)
pdsh@node00: node0: ssh exited with exit code 100

and so on for all other nodes.

The problem is the "apt update" command that require a sudo execution but I have not found a way to pass it with pdsh

The same kind of commands launched with "real" root user runs fine:

root@master:~$ pdsh -w root@node[0-3] apt update

But in this case this means actually enabling the "real" root user on all nodes, which I would like to avoid.

Is it posssible? Is there a way for running elevated privileges commands with pdsh without enabling the root user? Or are there alternative tools that can do this?

8
  • Is there a reason you can't run pdsh -w me@node[0-3] sudo apt update? Will it not ask for a password or something?
    – mchid
    Apr 3, 2020 at 17:00
  • 1
    If I run : me@node0:~$ pdsh -w me@node[0-3] sudo apt update This is the results: node0: sudo: no tty present and no askpass program specified pdsh@node0: node0: ssh exited with exit code 1 ... And so on for nodes 1, 2 and 3 :-\ B.
    – bed
    Apr 4, 2020 at 17:06
  • Thanks, it's just a guess but try this instead: pdsh -w me@node[0-3] sudo -S apt update If you still have trouble, try this: pdsh -w me@node[0-3] echo "password\n" | sudo -S apt update but replace password with your actual password and don't forget to put the new line character: \n after, as this is needed.
    – mchid
    Apr 4, 2020 at 17:36
  • Please let me know if this works and I will make it an answer. However, I will keep looking for a better solution in case you don't want your password in plaintext like this.
    – mchid
    Apr 4, 2020 at 17:38
  • Running pdsh -w me@node[0-3] sudo -S apt update the bash freezes waiting for something, then ctr-c : interrupt,.. command in progress node0... and nothing happens (other 2 ctrl-c for interrupt). For pdsh -w me@node[0-3] echo "password\n" | sudo -S apt update I think there is a typo, there must be a space, like this: pdsh -w me@node[0-3] echo "password" \n | sudo -S apt update; in any case the result is: [sudo] password for me: Sorry, try again. (3 times) and: [sudo] password for me: sudo: 3 incorrect password attempts Naturally the password is correct
    – bed
    Apr 5, 2020 at 15:33

2 Answers 2

0

You should be able to use the -S flag to pipe your password to sudo like this:

pdsh -w me@node[0-3] echo "password" | sudo -S apt update

where password is your actual password.

Also, you can prevent your password from showing up in your ~/.bash_history by placing the following line in your ~/.bashrc file:

export HISTIGNORE='*sudo -S*'

and don't forget to source your ~/.bashrc file to apply the changes:

source ~/.bashrc

You may need to do this on all machines.

1
  • Sorry... well there is something strange, if: pdsh -w me@node[0-3] echo "password" | sudo -S apt update the results is: [sudo] password for me: Sorry, try again. [sudo] password for bed: Sorry, try again. [sudo] password for bed: sudo: 3 incorrect password attempts as an incorrect password, but isn't :-/ I have read a similar solution (stackoverflow.com/questions/21659637/…) but for a ssh problem
    – bed
    Apr 10, 2020 at 17:37
0

Running on Red Hat, I run commands that require elevated privileges like this:

sudo /usr/local/bin/pdsh -w node[n-m] ?command

This should work as long as root has ssh access to other nodes.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .