Welcome to the Linux Foundation Forum!

05. Remote Access - some exercises for ssh and parallel-ssh

Chapter 5 gives some examples for ssh and parallel-ssh (pssh...). As a note, in Debian/Ubuntu etc. pssh etc. has been renamed to:
parallel-ssh
parallel-scp
parallel-slurp
etc.

I have 5 VMs running on my PC - master, worker1...worker4. The workers are Ubuntu 18.04 servers, so they use the /etc/netplan/...yaml file for network configuration. I had already manually configured all of them, except for the ~/.ssh/config file.

I created a ~/.ssh/config file on the host with the following content:

  1. Host master
  2. HostName 192.168.0.130
  3. User student
  4.  
  5. Host worker1
  6. HostName 192.168.0.131
  7. User student
  8.  
  9. Host worker2
  10. HostName 192.168.0.132
  11. User student
  12.  
  13. Host worker3
  14. HostName 192.168.0.133
  15. User student
  16.  
  17. Host worker4
  18. HostName 192.168.0.134
  19. User student
  20.  

I then ran the following script as an exercise:

  1. #!/bin/bash
  2. # Exercise using parallel-scp and parallel-ssh
  3. #
  4. # ips.txt contains the IP addresses of the hosts, one per line
  5. # -h hostfile -- provides list of hosts (IP addresses)
  6. # -i inline -- print output inline on localhost
  7. #
  8. # This script does the following:
  9. # 1. Copies the ~.ssh/config file on LOCALHOST to the remote hosts
  10. # specified in ips.txt.
  11. # 2. Shows the remote config files using cat.
  12. # 3. Deletes the remote config files.
  13. # 4. Shows the remote config files using cat - this gives an error.
  14. # 5. Copies again the ~.ssh/config file on LOCALHOST to the remote hosts.
  15. # 6. Shows the remote config files using cat.
  16.  
  17. parallel-scp -h ips.txt ~/.ssh/config /home/heiko/.ssh/
  18. parallel-ssh -ih ips.txt cat ~/.ssh/config
  19. parallel-ssh -ih ips.txt rm ~/.ssh/config
  20. parallel-ssh -ih ips.txt cat ~/.ssh/config
  21. parallel-scp -h ips.txt ~/.ssh/config /home/heiko/.ssh/
  22. parallel-ssh -ih ips.txt cat ~/.ssh/config
  23.  

Since I already defined aliases for all my VMs, I could also use the aliases inside ips.txt:

  1. worker1
  2. worker2
  3. worker3
  4. worker4
  5.  

The following is an exercise using parallel-slurp to copy remote files to the local host under ~/outdir:

  1. #!/bin/bash
  2. #
  3. # Copy /etc/netplan/0....yaml files on remote hosts to local host:
  4. parallel-slurp -L ~/outdir -h remhosts.txt /etc/netplan/0* .
  5. # Copy the /etc/hosts and /etc/hostname files to local host:
  6. parallel-slurp -L ~/outdir -h remhosts.txt /etc/hosts .
  7. parallel-slurp -L ~/outdir -h remhosts.txt /etc/hostname .
  8.  

Using the aliases, these files are then neatly stored in folders worker1...worker4.

I wonder if I could use pscp / parallel-scp to copy configuration stanzas to remote hosts and then manually change e.g. the IP. I'm talking specifically about the /etc/netplan/...yaml config file where I would have to change just the IP.

If I understand correctly, the IP would only change with the "netplan apply" command?

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Comments

  • Posts: 380

    Thank you for the suggestion !

  • Posts: 916

    Just as a footnote, the text already says names may be different, and I just checked on RHEL-8:

    1. c8:/home/coop/Desktop>rpm -qil pssh | grep bin
    2. /usr/bin/pnuke
    3. /usr/bin/prsync
    4. /usr/bin/pscp.pssh
    5. /usr/bin/pslurp
    6. /usr/bin/pssh
    7. c8:/home/coop/Desktop>
    8.  
  • Posts: 99

    Thanks for the response. I was trying to find out if pssh etc. were actually used for sysadmin tasks and tried to figure out a practical use case. As my experience = inexperience, I probably come up with all kinds of strange ideas on how to use commands.

    My post was by no means a critique, just my way of thinking and the hope that someone sets me straight, or confirms the possible use case.

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Categories

Upcoming Training