Подключиться к ssh из другого ssh через скрипт

Попробуйте:

find. \! \( -wholename "./build/*" -o -wholename./build \) -delete

Если вы запустите:

rm -rf /tmp/tmp2
mkdir /tmp/tmp2
cd /tmp/tmp2

mkdir -p build module/build source
touch.hidden build/abc build/abc2 source/def module/build/ghi

find. \! \( -wholename "./build/*" -o -wholename./build \) -delete

find.

ваш вывод будет:

./build
./build/abc

Это намного безопаснее, чем пытаться разобрать вывод ls, где вам нужно позаботиться об именах файлов или каталогов с пробелами или, что еще хуже, со встроенными символами новой строки, findобрабатывает их правильно.

0
12.08.2019, 16:38
2 ответа

Попробуйте просто сказать первому хосту выполнить команду sshвместо того, чтобы давать вам оболочку:

ssh -t -i private_key.pem ec2-user@ec2-11-11-111-11.us-west-2.compute.amazonaws.com ssh -t second_aws
0
28.01.2020, 03:22

То, что вы делаете, не открывает второе соединение из вашего экземпляра AWS. Он открывает соединение из того места, где запускается скрипт.

Вам следует искать опцию ProxyJump. Это позволит вам связать несколько SSH-соединений.

Вот выдержка со страницы man:

 ProxyJump
         Specifies one or more jump proxies as either [user@]host[:port] or an ssh URI.  Multiple proxies may be separated by comma characters and will be visited sequentially.  Setting this option will cause ssh(1) to connect
         to the target host by first making a ssh(1) connection to the specified ProxyJump host and then establishing a TCP forwarding to the ultimate target from there.

         Note that this option will compete with the ProxyCommand option - whichever is specified first will prevent later instances of the other from taking effect.

         Note also that the configuration for the destination host (either supplied via the command-line or the configuration file) is not generally applied to jump hosts.  ~/.ssh/config should be used if specific configuration
         is required for jump hosts.
0
28.01.2020, 03:22

Теги

Похожие вопросы