I need to write a script for some co-workers to connect over the following topology, using a private key for authentication (the same key for each person works on both bastion and db access):
┌────────────┐ ┌────────────┐ ┌────────────┐ ┌────────────┐
│ │ │ │ │ │ │ │
│ desktop │───>│ bastion │────>│ db access │────>│ db 3306 │
│ (windows) │ │ (linux) │ │ (linux) │ │ (mysql) │
└────────────┘ └────────────┘ └────────────┘ └────────────┘
My co-workers will then use this connection in a desktop db query tool.
To make this as easy to deploy as possible, I want to specify all the configuration on the command line without referring to any saved session data configured in the Putty UI. I have .ppk files for the private keys that the script can refer to.
What is the (probably very lengthy) putty and/or plink command line that will enable this?
From my interpretation of the manual, I've tried this:
plink -ssh -2 -i C:\temp\key.ppk -agent -A -t -l user -L 6035:127.0.0.1:6035 user@BASTION ssh -v -L 6035:DBHOST:3306 user@DBACCESS
That gets me to the bastion, but it then looks for a private key on the bastion to make the connection to db access.
I am able to connect to it with ssh from my Mac (code shown below), so I know that the current configuration of the boxes permits this kind of access. I am looking for a putty/plink solution for use for access from windows boxes.
ssh -v -A -t \
-L ${LOCAL_PORT}:localhost:${LOCAL_PORT} ${USER}@${BASTION_HOST} \
-t ssh -v -L ${LOCAL_PORT}:${DB_HOST}:${DB_PORT} ${USER}@${DB_ACCESS_HOST}
С выпуском PuTTY 0.68 plink
получил новый параметр командной строки
называется -proxycmd
. Использование этой новой функции дает более надежную и менее удобную
Загроможденное решение проблемы ИМХО.
К сожалению, вариант -proxycmd
не помогает. Оно делает
выполнить локальную команду и использовать ее как прокси. Можно использовать даже plink
с параметром -nc
для создания туннеля до хоста db access
.
Для вашей топологии команда, выполняемая на рабочем столе
, выполняет это на
командная строка выглядит следующим образом:
plink -A ^
-proxycmd "plink -A -nc DBACCESS:22 user@BASTION" ^
-L 6035:DBHOST:3306 ^
user@DBACCESS
Примечание. Для входа без пароля peagent
должен быть запущен на рабочем столе
host и загрузите соответствующие ключи. Как уже упоминалось в
комментариев, переадресация агента должна быть включена на хостах бастиона
на
сделайте так, чтобы он работал без проблем.
Соединение выглядит так, как показано на рисунке ASCII ниже. Внешний
туннель идет к хосту доступ к базе данных
через команду прокси.
Инкапсулированный в туннеле запускает plink
и устанавливает
порт переадресован на хост db
.
┌────────────┐ ┌────────────┐ ┌────────────┐ ┌────────────┐
│ │ │ │ │ │ │ │
│ ───────────────────────────── │ │ │
│ (1) │ │ │
│ ──────────────────────────────────────────── │
│ (2) │
│ ──────────────────────────────────────────── │
│ ───────────────────────────── │ │ │
│ desktop │ │ bastion │ │ db access │ │ db 3306 │
│ (windows) │ │ (linux) │ │ (linux) │ │ (mysql) │
└────────────┘ └────────────┘ └────────────┘ └────────────┘
1) Tunnel via `-proxycmd "plink -A -nc DBACCESS:22 user@BASTION"`
2) Proxied `plink` connection with port forward `-L 6035:DBHOST:3306`