1
0

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 を開く ssh_config 設定

Last updated at Posted at 2023-11-02

~/.ssh/config を次のように編集する:

~/.ssh/config
Host hoge
  Hostname baa

  RequestTTY force
  RemoteCommand [[ $(tmux list-sessions | grep -q "^0:"; echo $?) == 0 ]] && tmux a -t 0 || tmux

ログインと同時に tmux session 0 に入り、tmux デタッチすると SSH もログアウトされる。

tmux デタッチ後も SSH セッションを保持したい場合は、RemoteCommand 末尾に bash -l を加える:

  RequestTTY force
  RemoteCommand [[ $(tmux list-sessions | grep -q "^0:"; echo $?) == 0 ]] && tmux a -t 0 || tmux; bash -l
1
0
0

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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?