Teratermの利用時に有用な小技をいくつかまとめます。
Teratermマクロを使ったログイン
Teraterm用にログイン情報をマクロファイル(.ttl)に設定しておくことで、毎回のサーバー接続時の作業 (ターミナルの起動→接続先(アドレス/ポート)の入力→接続IDの指定, パスワードの入力またはキーファイルの指定)がマクロの実行だけで済みます。
ログイン操作は、connectを使用します。
connect [アドレス]:[ポート] /ssh /auth=(publickey|password)/user=userid (/passwd=パスワード, /keyfile=.pemファイル名)
Teratermマクロに記載する例
connect ec2-11-22-33-44.ap-northeast-1.compute.amazonaws.com:22 /ssh /2 /auth=publickey /user=ec2-user/keyfile=C:\work\keyfile\ec2-key.pem
connect '22.33.44.55:22 /ssh /auth=password /user=test-user /passwd=password'
マクロファイル(.ttl)の関連付け
.ttlファイルをTeratermマクロttpmacro.exeと関連付けすることで、.ttlファイルをダブルクリックするだけでログインできます。
プログラムから開く> 別のプログラムを選択 > アプリを選択して.ttlファイルを開く > PCでアプリを選択する を選択後、ttpmacro.exeを選択します。
Teraterm設定内容の保管
Teratermの設定はメニューから変更できますが、変更内容は Teratermを終了すると消えてしまいます。
Teraterm終了後も変更内容を継続して利用する場合は、変更をTeraterm.iniファイルに保存できます。
Teratermのメニューから、
Teraterm起動時 iniファイルの指定
次回起動時に、このファイルが読み込まれることで、ファイル保管時の変更(例えばフォント、色/背景色、ウインドウのサイズや接続席の履歴等)を、利用することができます。
connect '22.33.44.55:22 /ssh /auth=password /user=test-user /passwd=password' /F=C:\Teraterm\teraterm.ini
ログイン後のキー入力
connect '22.33.44.55:22 /ssh /auth=password /user=test-user /passwd=password' /F=C:\Teraterm\teraterm.ini
if result <> 2 then
messagebox 'It could not be connected.' 'Connected error'
end
endif
;; 10秒以内にプロンプトが表示されない場合終了
timeout = 10
wait '$' '#'
if result = 0 then
disconnect
end
endif
;; backservにtestuserでSSH接続
sendln 'ssh testuser@backserv'
;; 「password:」が表示されたらパスワードを入力
wait 'password:'
sendln 'hogehoge'
wait '$' '#'
内容はTERATERMマクロのファイル(.ttl)として保管。
拡張子をttpmacro.exeに関連付け
teratermマクロの実行時は、ttpmacro.exe [マクロファイル].ttl
で実行できますが、この拡張子.ttl
をttpmacro.exeと関連付けしておくことで、ファイルのダブルクリックでログインできるようになります。