
ssh -vvv -F /home/me/.ssh/config serva -t "source ~/.bashrc"
-vvv
これはフラグを使用したときに得られる出力です。
debug1: Authentication succeeded (publickey).
debug1: channel 0: new [client-session]
debug3: ssh_session2_open: channel_new: 0
debug2: channel 0: send open
debug1: Requesting [email protected]
debug1: Entering interactive session.
debug3: Wrote 128 bytes for a total of 2413
debug2: callback start
debug2: client_session2_setup: id 0
debug2: channel 0: request pty-req confirm 1
debug1: Sending command: source ~/.bashrc
debug2: channel 0: request exec confirm 1
debug2: fd 3 setting TCP_NODELAY
debug2: callback done
debug2: channel 0: open confirm rwindow 0 rmax 32768
debug3: Wrote 400 bytes for a total of 2813
debug2: channel_input_status_confirm: type 99 id 0
debug2: PTY allocation request accepted on channel 0
debug2: channel 0: rcvd adjust 2097152
debug2: channel_input_status_confirm: type 99 id 0
debug2: exec request accepted on channel 0
debug1: client_input_channel_req: channel 0 rtype exit-status rep
ly 0
debug1: client_input_channel_req: channel 0 rtype [email protected]
reply 0
debug2: channel 0: rcvd eow
debug2: channel 0: close_read
debug2: channel 0: input open -> closed
debug2: channel 0: rcvd eof
debug2: channel 0: output open -> drain
debug2: channel 0: obuf empty
debug2: channel 0: close_write
debug2: channel 0: output drain -> closed
debug2: channel 0: rcvd close
debug3: channel 0: will not send data after close
debug2: channel 0: almost dead
debug2: channel 0: gc: notify user
debug2: channel 0: output drain -> closed
debug2: channel 0: rcvd close
debug3: channel 0: will not send data after close
debug2: channel 0: almost dead
debug2: channel 0: gc: notify user
debug2: channel 0: gc: user detached
debug2: channel 0: send close
debug2: channel 0: is dead
debug2: channel 0: garbage collecting
debug1: channel 0: free: client-session, nchannels 1
debug3: channel 0: status: The following connections are open:
#0 client-session (t4 r0 i3/0 o3/0 fd -1/-1 cfd -1)
debug3: channel 0: close_fds r -1 w -1 e 6 c -1
debug3: Wrote 32 bytes for a total of 2845
debug3: Wrote 64 bytes for a total of 2909
サーバー側のログには、次のメッセージがあります。sshd[18763]: Received disconnect from
...
CentOS 6.4を使用しています。
編集する
私の元の質問に欠陥がありました。すみません。必要なrcファイル(〜/ .bashrc_temp)でbashシェルを実行してから、別のエントリを実行したいと思います。 PROMPT_COMMANDが推奨オプションのように見える場合、または//.bashrc_temp自体内でコマンドを実行するのは理想的ではありませんが、いくつかの条件文を追加することもできます。
答え1
これを行うとき:
ssh serva -t "source ~/.bashrc"
ssh
sshd
次のようにリモートユーザーのログインシェルを呼び出すように指示します。
the-shell -c 'source ~/.bashrc'
これにより、シェルにコマンドの実行と終了を指示します。
おそらくあなたが望むのは、対話型シェルを実行し、その対話型シェルにコマンドをsource ~/.bashrc
実行させることです。それからプロンプトを発行し、実行するコマンドをさらに読んでください。
まず、インタラクション時source ~/.bashrc
にソースbash
がすでに提供されているため、これは不要です~/.bashrc
(実際には非ssh
対話型であってもこれが行われます)。だから:
ssh serva
十分。
これで、コマンドを実行してからインタラクティブシェルを実行するには、次のことができます。
ssh -t serva 'cmd; bash'
(実行するコマンドを渡すときにデフォルトでは擬似端末が起動しない-t
ため必要です)ssh
cmd
ただし、実行されませんbash
(コマンドラインを解釈するためにsshd(ログインシェル)によって開始されたシェルによって実行されますcmd; bash
)。
bash
インタラクティブにコマンドを実行したい場合。 1つの秘訣はbash
s変数を使用することですPROMPT_COMMAND
。bash
この変数の内容を、各プロンプトの前に実行されるシェルコードとして解釈します。だからあなたはこれを行うことができます:
ssh -t serva 'PROMPT_COMMAND="cmd; unset PROMPT_COMMAND" bash'