teketeke_55の日記

技術メモとか

Logmettマクロめも【teraterm】

自動ログイン

パスワード認証
 ; ******* LogMeTT Macro Template for SSH2 session *******
 ; setting
 
 hostname = 'xxxx'
 username = 'xxxx'
 getpassword 'C:\Users\xxx\Documents\teraterm\terapass.txt' hostname inputstr
 
 ; Openning SSH2 connection using port 22.
 ; User will be prompted for username and password
 
 ; connection & login
 msg = hostname
 strconcat msg ':22 /ssh /2 /auth=password /user='
 strconcat msg username
 strconcat msg ' /passwd='
 strconcat msg inputstr
 connect msg
 settitle 'Connected to xxx'
 
 ; Entering synchronous communication mode(useful in most cases)
 setsync 1

※getpasswordのファイルを指定することでパスワード入力を省略できる。デフォルトでは暗号化される

鍵認証 >||

; ******* LogMeTT Macro Template for SSH2 session *******
; Openning SSH2 connection using port 22.
; User will be prompted for username and password
; setting

hostname = 'xxx'
username = 'xxx'
keyfile = 'C:\Users\xxx\Documents\teraterm\xxx_id_rsa'
getpassword 'C:\Users\xxx\Documents\teraterm\terapass.txt' hostname inputstr

; Openning SSH2 connection using port 22.
; User will be prompted for username and password

; connection & login
msg = hostname
strconcat msg ':22 /ssh /2 /auth=publickey /user='
strconcat msg username
strconcat msg ' /passwd='
strconcat msg inputstr
strconcat msg ' /keyfile='
strconcat msg keyfile
connect msg
settitle 'Connected to xxx.xxx'

; Entering synchronous communication mode(useful in most cases)
setsync 1
|

多段login

logmettで踏み台の配下に以下のマクロを設置する。

 ; ******* LogMeTT Macro Template for SSH2 session *******
 ; Openning SSH2 connection using port 22.
 ; User will be prompted for username and password
 ; setting
 
 ;; 2段目のSSH接続
 host_2nd = 'xxx@xxx' ; 目的のサーバー(2回目のSSH先)のユーザー名とホスト名。例)otp@xxx.xxx.xxx.xxx
 remote_prompt = '$' ; シェルのプロンプトを指定する。bash系なら「$」、cshなら「%」、tcshなら「>」など
 
 ssh_command = 'ssh '
 strconcat ssh_command host_2nd
 hostname = 'xxx'
 ;username = 'xxx'
 msg = hostname
 passwd_prompt = 'pass'
 connect msg
 
 getpassword 'C:\Users\xxx\Documents\teraterm\terapass.txt' hostname inputstr
 
 wait remote_prompt
 sendln ssh_command
 wait passwd_prompt
 sendln inputstr