2
1

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 3 years have passed since last update.

SSHで接続した後に特定のディレクトリに移動したい

Posted at

プロジェクトごとのSSHで、あるサーバにログインした後、デプロイを行っているディレクトリに移動する、というスクリプトを書きたかったです。

$ ssh ssh.example.com -t 'cd tmp; bash --login'

cdコマンドをsshの引数として渡すとcdが実行された後にsshコマンドが終了してきて戻ってきてしまいます。

-tオプションを付けてsshを起動し、cd した後に bash --login をするとcdが終了した後にbashが起動され、引き続きターミナルを使うことができます。

-tForce pseudo-terminal allocation.となっており、擬似端末(PTY)を強制的に割り当てるため、bash --loginがPTY上でcdしたセションが残ります。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?