1つのコマンドですべてのSSH接続を終了し、PuTTYを閉じます。

1つのコマンドですべてのSSH接続を終了し、PuTTYを閉じます。

すべてのSSH接続を終了して閉じる方法はありますか?パテ「ワンショット」で?私は Windows 7 で作業しており、PuTTY を使用してさまざまな Linux ホストに SSH で接続しています。

私がどのように仕事をしているかの一例:

SSH to host1 with PuTTY...
banjer@host1:~> #...doin some work...ooh! need to go check something on host8...
banjer@host1:~> ssh host8
banjer@host8:~> #...doin some work...OK time for lunch. lets close putty...
banjer@host8:~> exit
banjer@host1:~> exit
Putty closes.

上記のように、ホスト 8 から PuTTY を 1 回で閉じる方法はありますか? ときには、ホストが 5 台または 10 台まで深くなることがあります。X をクリックして PuTTY ウィンドウを閉じることができることはわかっていますが、exit コマンドを使用して SSH 接続が適切に閉じられていることを確認したいのです。また、怠惰を増やす方法についてのヒントを求めていることもわかっています。「どうすればもっと効率的にできるか」とだけ書き添えておきます。

答え1

接続終了エスケープ シーケンスを使用してみてくださいssh

セッションでssh~.(チルダ ドット) を入力します。入力した文字は表示されませんが、セッションはすぐに終了します。

$ ~.
$ Connection to me.myhost.com closed.  

からman 1 ssh

The supported escapes (assuming the default ‘~’) are:
 ~.      Disconnect.
 ~^Z     Background ssh.
 ~#      List forwarded connections.
 ~&      Background ssh at logout when waiting for forwarded 
         connection / X11 sessions to terminate.
 ~?      Display a list of escape characters.
 ~B      Send a BREAK to the remote system (only useful for SSH protocol
         version 2 and if the peer supports it).
 ~C      Open command line.  Currently this allows the addition of port 
         forwardings using the -L, -R and -D options (see above). It also
         allows the cancellation of existing remote port-forwardings using 
         -KR[bind_address:]port.  !command allows the user to execute a 
         local command if the PermitLocalCommand option is enabled in
         ssh_config(5).  Basic help is available, using the -h option.
 ~R      Request rekeying of the connection (only useful for SSH protocol 
         version 2 and if the peer supports it).

答え2

Ctrl+を押すだけDで終了し、ログアウトします。押したまま繰り返しCtrl押すとD、ウィンドウが消えるまで複数のウィンドウ、タブ、またはレベルからログアウトします。

答え3

PuTTY を閉じるだけです。(デフォルトではAlt+ です。)F4

答え4

別の方法としては、次のfunctionようになりますssh

   function ssh(){ /usr/bin/ssh $@ ; exit ; } 

残念ながら、リモート システムでの作業が終了すると、常に接続が閉じられ、コンソールからログアウトされます。

注意: すべてのサーバーでこのような関数を作成する必要があります。そうしないと、このハックは機能しません。ちなみに、関数はいつでも ~/.bashrc または ~/.whatever_shell_you_use_rc に置くことができます。

uther の方法と比較すると、少し汚いハックのように見えます。

関連情報