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

サーバの sshd とは別にもう一つ OpenSSH サーバを立てる

Posted at

「OpenSSH の特定のバージョンをテストしたい」でも「いま動いている SSH サーバは OS のアップデートで管理したいので、置き換えたいわけではない」となることがありますよね。
そんなとき、いま port 22 で listen している sshd とは別に、OpenSSH サーバをソースからビルドして、別ポートでもう1つ sshd を立てるにはどうするのか、その手順をまとめてみます。

方針

  • システムの openssh を上書きしない
    • /usr/local の下の別フォルダにインストールする
    • /etc/ssh は参照しない
  • OS のユーザで認証する
  • 常用するわけではないので systemctl の用意などはしない

コンパイル

試した環境は、手元にあった AlmaLinux 9 です。
暗号ライブラリは元々入っている OpenSSL 3.0.1 を使用します。

$ rpm -q openssl
openssl-3.0.1-43.el9_0.x86_64

コンパイラや、コンパイルに必要なヘッダを入れます。

$ dnf install gcc zlib-devel openssl-devel pam-devel

OpenSSH 9.6 のソースを入手してコンパイルします。

$ wget https://cloudflare.cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-9.6p1.tar.gz
$ tar zxvf openssh-9.6p1.tar.gz
$ cd openssh-9.6p1
$ ./configure \
--prefix=/usr/local/openssh-9.6 \
--with-pam \
--with-ssl-engine
$ make
$ sudo make install

/usr/local/openssh-9.6/{bin,sbin,libexec,share,etc} にインストールされました。
また、make install の途中で /usr/local/openssh-9.6/etc にサーバホスト鍵が自動的に作成されたので、システムの /etc/ssh が参照されないこともわかります。

起動

先に firewall を空けておかないと外部から接続できません。

$ sudo firewall-cmd --add-port=2296/tcp --zone=public

sshd を起動します。設定変更は /usr/local/openssh-9.6/etc/sshd_config を編集してもいいですが、引数でも指定できます。

  • -d -d -d オプションで debug3 ログまで出力します
  • -p オプションでポート番号を指定します
$ sudo /usr/local/openssh-9.6/sbin/sshd -4 -d -d -d -e -p 2296

クライアントから接続して SSH が切断されると sshd は終了します。

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