Created
April 7, 2022 10:14
-
-
Save jn0/fa0b8e89c56f275cccd4af709c4a76ef to your computer and use it in GitHub Desktop.
how to reuse ssh session (and do not enter password more than once)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# from https://serverfault.com/a/842825/200976 | |
# Create ssh-mux (SSH multiplex) dir only if not exists | |
[[ ! -d dir ]] || mkdir ~/.ssh/ssh-mux | |
apache_site_path_source="/var/www/source_site" | |
apache_site_path_target="/var/www/target_site" | |
# Solution: Start SSH multiplexing session (works fine) | |
# https://unix.stackexchange.com/questions/50508/reusing-ssh-session-for-repeated-rsync-commands | |
sudo ssh -nNf -o ControlMaster=yes -o ControlPath="~/.ssh/ssh-mux/%L-%r@%h:%p" root@192.168.0.1 | |
sudo rsync -av --progress -e 'ssh -l root -p 22 -o "ControlPath=~/.ssh/ssh-mux/%L-%r@%h:%p"' 192.168.0.1:${apache_site_path_source}/. ${apache_site_path_target}/; | |
printf "\n\n\n\n\n\n" | |
sudo rsync -av --progress -e 'ssh -l root -p 22 -o "ControlPath=~/.ssh/ssh-mux/%L-%r@%h:%p"' 192.168.0.1:${apache_site_path_source}/. ${apache_site_path_target}/; | |
printf "\n\n\n\n\n\n" | |
sudo rsync -av --progress -e 'ssh -l root -p 22 -o "ControlPath=~/.ssh/ssh-mux/%L-%r@%h:%p"' 192.168.0.1:${apache_site_path_source}/. ${apache_site_path_target}/; | |
printf "\n\n\n\n\n\n" | |
# Finish SSH multiplexing session | |
sudo ssh -O exit -o ControlPath="~/.ssh/ssh-mux/%L-%r@%h:%p" root@192.168.0.1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment