ブラックボックス

プログラミングのノウハウやライフハックをどんどん投稿していきたい

Sep 19, 2013 - 1 minute read - ノウハウ

【SSH】Tera Termマクロで簡単ログイン 秘密鍵使用編

以前 認証がプレーンテキストの場合のマクロを紹介しましたが、秘密鍵を使用している場合のマクロも紹介します。

拡張子をttl、ttlをttpmacro.exeに関連付けをし、以下を保存。

username = 'user'
hostname = '192.168.0.2'
passwdfile = 'C:\pswd.dat'
keyfile = 'C:\id_rsa'

msg = 'Enter password for user '
strconcat msg username
passwdkey = username
strconcat passwdkey '@'
strconcat passwdkey hostname
getpassword passwdfile passwdkey password

msg = hostname
strconcat msg ':22 /ssh /auth=publickey /user='
strconcat msg username
strconcat msg ' /passwd='
strconcat msg password
strconcat msg ' /keyfile='
strconcat msg keyfile

connect msg

基本的に最初の4行目を環境に合わせて書き換えれば動くようになっているはずです。
username……SSHでログインしたいユーザ
hostname……接続先
passwdfile……パスワードを保存するファイル
keyfile……秘密鍵のある位置