4
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.

sshd(OpenSSH)の振る舞い方

Last updated at Posted at 2021-06-19

sshで接続したリモートホストにおいて、ps, pstreeコマンドでプロセスの詳細を見てみると、bashプロセスを起動するまでにsshdプロセスが3つも展開されていることがわかる。

ssh接続前

pstree -p | grep sshd

 |-sshd(844)

ssh接続後

ps aux | grep sshd

root         844  0.0  0.5  92332  7624 ?        Ss    6月19   0:00 /usr/sbin/sshd -D
root       10077  0.0  0.7 153424 10336 ?        Ss   23:53   0:00 sshd: root [priv]
root       10081  0.0  0.4 153424  5596 ?        S    23:53   0:00 sshd: root@pts/0
root       10105  0.0  0.0  10308  1152 pts/0    R+   23:54   0:00 grep --color=auto sshd
pstree -p | grep sshd

 |-sshd(844)---sshd(10077)---sshd(10081)---bash(10082)-+-grep(10147)

ssh接続前と接続後のpstreeを見ての通り、initプロセスの子プロセスであるsshd(844)はssh接続を監視しているプロセスである。(正確にはデーモンではない?)
そしてこのsshd(844)が、sshコネクションごとにsshdプロセスを展開していきそうな気もするが、
pstreeでプロセスの親子関係を見てみると、bashプロセスの前にもう1つsshd(10081)がある。
このプロセスについては、psコマンドにおいて[prev]となっていることから、特権モードで起動しているsshdプロセスであることがわかる。

以上より、セキュリティ的な観点から、認証とセッションなどの管理を特権モードのsshdプロセスと非特権モードのsshdで役割分担していると考えられる。

まとめると、ssh接続においてshellが起動するまでの流れは以下のようになる。

  1. initプロセス直下のsshdがssh接続を監視。
  2. ssh接続要求ごとに、1のsshdが子プロセスとして新たなsshdを特権モードで起動。
  3. 2のsshdが認証を行う。
  4. 認証成功後、3のsshdの子プロセスとしてsshdを非特権モードで起動。
  5. 4のsshdの子プロセスとしてshellが起動される。
4
1
1

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