3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ssh接続と同時に自動でtmux/screenのセッションにアタッチ

Last updated at Posted at 2022-12-22

いろいろと何時間も調べたら

自動でセッションにアタッチ
% ssh <host> -t tmux attach
or
% ssh <host> -t tmux attach -t <session name>

-tオプションを付けるだけだという事が分かった。。。
通常の-tなしだとtmux/screenの様な(仮想)端末使用のコマンドは実行に失敗してsshの接続を終了してしまう。

いつも接続するリモートマシンにはこのコマンド自体のaliasを作っておくと良いだろう。

Alias例(bash)
alias ssh_HOSTA_S0='ssh my_hostA -t tmux attach -t 0'

又、以下の様にtmuxのセッションが既にあればそれにアッタッチ、なければ新たに作る、の様なシェルスクリプトを作っておいてそれを実行するようにすると良いかもしれない。

そしてこれ書いた後いろいろ探してたらここに答え載ってた。。。

そしてtmux/screenについていろいろ調べたらbyobuと言うコマンドがある事を知る。もしbyobuが使えたら生のtmuxよりそれを使う方が断然便利。上記のスクリプトのセッションが既にあるかないかの判断もbyobuがやってくれる。

byobuを使って自動的にセッションにアタッチ
% ssh <host> -t byobu
3
2
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?