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

ssh でログイン先でも今いるディレクトリにすぐに移動

2
Last updated at Posted at 2016-03-02

nfs とかで同じディレクトリ構成の複数のホスト間を行き来することが多い。
ログイン先でも $HOME じゃなくて、今いるディレクトリに移動したいのでメモ。

コマンドとしては ssh -t を使って、 PWD_TMP という変数に PWD をセットして、ログインシェルを実行する。

ssh -t HOST "export PWD_TMP=$PWD ; /bin/zsh"

ログインシェルの rc ファイルとかに PWD_TMP が設定されて、ディレクトリが存在するならば、cd する。

.zshrc
if [ -d $PWD_TMP ] ; then
	cd $PWD_TMP ;
fi

毎回入力しなくてもいいように、適当にホスト名とかで alias を設定しておく。

.zshrc
alias xxxx='ssh -t HOST "export PWD_TMP=$PWD ; /bin/zsh"'

注意すべきは zsh の .zprofile は呼ばれないので、ここに色々書いている人は注意が必要。

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