Chao's blog

Memos of daily programming

Go to content
Search
Search
Back to top

Tera Term:auto login using macro through SSH forwarding

2017-06-27 2017-06-27

At times we need to access(ssh) a target server using a proxy with SSH fowarding.
The login process can be done automatically using the Tera Term macro,TTL(Tera Term Language)
Here are the steps.

■Setting up the SSH forwarding and save the TERATERM configuration file(TERATERM.INI)

Setup SSH Port Forwarding
Setup SSH Port Forwarding
Save configuration file
Save configuration file

■Create a macro file(e.g. CONNECT-TO-TARGET-SERVER.TTL) with the following content.
Two private key files (one for each server) and the saved TERATERM.INI file in the above step are supposed to in the same directory with the TTL file.

proxyServer='YOUR PROXY SERVER'
proxyServerUserName='YOUR PROXY SERVER USER NAME'
proxyServerkeyFileName='YOUR PROXY SERVER PRIVATE KEY FILE NAME WITHOUT PATH'
targetServerTunnelPort='10022' /* YOUR LOCAL PORT*/
targetServerUserName='YOUR TARGET SERVER USER NAME'
targetServerkeyFileName='YOUR TARGET SERVER PRIVATE KEY FILE NAME WITHOUT PATH'

getdir dir

;connect to the proxy server
sprintf2 connectStr '%s /ssh /auth=publickey /user=%s /keyfile=%s/%s /F=%s/TERATERM.INI' proxyServer proxyServerUserName dir proxyServerkeyFileName dir
connect connectStr

unlink

;connect to the target server 
sprintf2 connectStr 'localhost:%s /ssh /auth=publickey /user=%s /keyfile=%s/%s' targetServerTunnelPort targetServerUserName dir targetServerkeyFileName
connect connectStr

■Double click the macro file(CONNECT-TO-TARGET-SERVER.TTL)
Before that,you need to associate the TTL file extension with the app of ttpmacro.exe but not ttermpro.exe

Proudly powered by WordPress. Theme digitale Pracht by Palasthotel.