Cygwin is a MS-Windows program that provides a POSIX virtual environment, including but not limited to: posix c api, shell and most famous command line programs.
With the free combination of various gadgets, it can replace the SSH remote logon GUI tool SecureCRT.
Principle:
MS-Windows (win)-jumper-target machine
- Start openssh server on the pedal
- Run autossh on win and create a persistent TCP connection between win and jumper to implement the SOCKS5 Proxy
- Use openssh to connect to the target machine through jumper on win
Procedure
Use cygwin setup.exe to install the following package
net - nc - openssh - ssheditors - vim
Take a user named "bot" as an example to configure the home Directory
ln -s /cygdrive/c/Users/bot /home/mkdir -p ~/bin
Ssh client configuration ~ /. Ssh/config
GSSAPIAuthentication noConnectTimeout 5KeepAlive yesServerAliveInterval 60Compression yesCompressionLevel 5ForwardAgent yesHost from="*.exmaple.com" User bot Port 22 ForwardAgent yes ProxyCommand /bin/nc -x 127.0.0.1:7070 %h %p
When you use ssh to connect a host that ends with exmaple.com as the domain name suffix, it will be connected through the SOCKS5 Proxy 127.0.0.1: 7070.
Configure bash ~ /. Bash_profile
...export PATH=$PATH:$HOME/binbash ~/bin/auto-start-ssh-agent.shsource ~/bin/auto-config-ssh-agent-env.sh
Compile and implement the SOCKS5 Proxy script ~ // Bin/start-jumper-daemon.sh
#! /Usr/bin/env bashautossh-M20000-f-C-D 7070-N-q-A-p 22 Jump Server user @ jump Server IP Address
Execute this script to start two background processes. One process creates a persistent TCP connection between the Windows server and the stepping stone server, and the other monitors. If an error occurs, the system automatically reconnects. Generally, you can run the command once after each boot.
Ssh-agent configuration ~ // Bin/auto-start-ssh-agent.sh
#!/usr/bin/env bashSSH_AUTH_SOCK_DEFAULT=/tmp/ssh-agent.sockif ps aux | grep ssh-agent > /dev/null; then :else rm $SSH_AUTH_SOCK_DEFAULT > /dev/null ssh-agent -a $SSH_AUTH_SOCK_DEFAULTfisource ~/bin/auto-config-ssh-agent-env.shssh-add -L > /dev/null || ssh-add
Ssh-agent configuration II ~ // Bin/auto-config-ssh-agent-env.sh
#!/usr/bin/env bashexport SSH_AUTH_SOCK=/tmp/ssh-agent.sockexport SSH_AGENT_PID=`ps aux |grep ssh-agent |awk '{print $1}'`
Description
- After the ssh-agent is started
SSH_AUTH_SOCK
AndSSH_AGENT_PID
Two Environment Variables
- Ssh pass detection
SSH_AUTH_SOCK
AndSSH_AGENT_PID
Two environment variables are used to determine whether there is an ssh-agent background process. If there is an ssh-agent background process, use ssh-agent for automatic authentication. Otherwise, the user is prompted to enter the password.
- The environment variables set after the ssh-agent is started only exist in the current mintty window session, and the newly started window does not inherit or automatically detect
- Auto-config-ssh-agent-env.sh through hard-coded ssh-agent unix domain socket path, realize dynamic automatic setting environment variable