There are two ways to achieve this: 1) install spawn and CT first. Run sudoapt-getinstallexpectspawn and input the following script to a text file, such as fanqiang. ssh :#! /Usr/bin/expectsettimeout60spawn/usr/bin/ssh-pserverport-D1 here there are two ways to achieve 1) first install spawn and CT. Run:
Sudo apt-get install verify CT spawn
Then input the following script into a text file, such as fanqiang. ssh:
#! /Usr/bin/expectset timeout 60 spawn/usr/bin/ssh-p
Serverport-D 127.0.0.1: 7070-g username @
ServeripReset CT {"password:" {send"
Password\ R "}}interact {timeout 60 {send ""}}
Then grant the execution permission:
Chmod + x fanqiang. ssh
Run the following command:
./Fanqiang. ssh
In this way, we have completed a redirection, but there is a drawback in this process, that is, it cannot be executed in the background. Once the shell window is closed, the corresponding process will end. Next we will introduce another method that can be executed in the background.
2) first install the required putty-tools Package and execute:
Sudo apt-get install putty-tools
Then write the following script into a file, such as fanqiang2.ssh:
Nohup plink-P
Serverport-N
Username@
Serverip-Pw
Password-D 127.0.0.1: 7070 &
Then grant the execution permission:
Chmod + x fanqiang2.ssh
Run the following command:
./Fanqiang2.ssh
Now, even if we close the shell window, background processes still exist. It has no effect on us.
Note: The bold font involved in the code above indicates:
ServeripIP address or domain name used to connect to the server
ServerportPort connecting to the server
UsernameUser Name of your SSH account
PasswordYour SSH account password