以下の内容はhttps://kazuhira-r.hatenablog.com/entry/2026/03/20/160714より取得しました。


sshd-liteでシングルバイナリーで簡易的なSSHサーバーを使う

これは、なにをしたくて書いたもの?

ちょっとした動作確認などで使えるシングルバイナリーで動くSSHサーバーを探していたのですが、なかなか見つからず。

作った方がいいのかなと思ったのですが、求めるものが見つかったので簡単に確認しておこうかなと。

sshd-lite

見つけたのはsshd-liteです。

GitHub - jpillora/sshd-lite: A feature-light sshd(8) for Windows, Mac, and Linux written in Go · GitHub

Goで書かれた、Linux、macOS、Windowsで動作するSSHサーバーです。

探していたのがシングルバイナリー、クロスプラットフォームで動作するものだったのでGoあたりでしょうと思っていたの
ですが、やっぱりそうですね。

Go and the Secure Shell protocol | Gopher Academy Blog

ただsshd-liteは実験的なものなので、本格的に使うのなら以下あたりを使って自分で作った方がいいのでしょうね。

GitHub - gliderlabs/ssh: Easy SSH servers in Golang · GitHub

GitHub - charmbracelet/wish: Make SSH apps, just like that! 💫 · GitHub

JavaならApache MINA SSHDでしょう。

SSHD Overview — Apache MINA

では、sshd-liteを使ってみます。

環境

今回の環境はこちら。Ubuntu Linux 24.04 LTSです。

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 24.04.4 LTS
Release:        24.04
Codename:       noble


$ uname -srvmpio
Linux 6.8.0-106-generic #106-Ubuntu SMP PREEMPT_DYNAMIC Fri Mar  6 07:58:08 UTC 2026 x86_64 x86_64 x86_64 GNU/Linux

SSHクライアントして使う

sshd-liteをインストールして使ってみる

sshd-liteのインストール方法は、バイナリーをダウンロードするかcurl+bashでのインストールになります。

sshd-lite / Install

今回はreleasesからバイナリーをダウンロードしてみます。

$ curl -LO https://github.com/jpillora/sshd-lite/releases/download/v1.31.0/sshd-lite_1.31.0_linux_amd64.gz

展開して実行権限を付与。

$ gunzip sshd-lite_1.31.0_linux_amd64.gz
$ chmod +x sshd-lite_1.31.0_linux_amd64

バージョン。

$ ./sshd-lite_1.31.0_linux_amd64 --version
1.31.0

ヘルプ。

$ ./sshd-lite_1.31.0_linux_amd64 --help

  Usage: sshd-lite [options] <auth>

  <auth> must be set to one of:
  1. a username and password string separated by a colon ("myuser:mypass")
  2. a path to an ssh authorized keys file ("~/.ssh/authorized_keys")
  3. an authorized github user ("github.com/myuser") public keys from .keys
  4. "none" to disable client authentication :WARNING: very insecure

  Options:
  --host, -h            listening interface (defaults to all, default 0.0.0.0)
  --port, -p            listening port (defaults to 22 then fallsback to 2200)
  --shell               the shell to use for remote sessions (default bash/powershell, env SHELL)
  --workdir, -w         working directory for sessions (default current directory)
  --keyfile, -k         a filepath to a private key (for example an 'id_rsa' file)
  --keyseed             a string to use to seed key generation (env KEYSEED)
  --keyseed-ec          use elliptic curve for key generation (env KEYSEED_EC)
  --keepalive           server keep alive interval seconds (0 to disable, default 60)
  --noenv, -n           ignore environment variables provided by the client
  --verbose, -v         verbose logs
  --quiet, -q           no logs
  --sftp, -s            enable the SFTP subsystem (disabled by default)
  --tcp-forwarding, -t  enable TCP forwarding (both local and reverse; disabled by default)
  --version             display version
  --help                display help

  Notes:
  * if no keyfile and no keyseed are set, a random RSA2048 key is used
  * authorized_key files are automatically reloaded on change
  * once authenticated, clients will have access to a shell of the
    current user. sshd-lite does not lookup system users.
  * sshd-lite only supports remotes shells, sftp, and tcp forwarding. command
    execution are not currently supported.
  * sftp working directory is the home directory of the user

  Version:
    1.31.0

  Read more:
    github.com/jpillora/sshd-lite

デフォルトでは全アドレス、2200ポートにバインド、シェルはBashまたはPowerShell、環境変数SHELL、そして
作業ディレクトリーはカレントディレクトリーになるという感じですね。

  --host, -h            listening interface (defaults to all, default 0.0.0.0)
  --port, -p            listening port (defaults to 22 then fallsback to 2200)
  --shell               the shell to use for remote sessions (default bash/powershell, env SHELL)
  --workdir, -w         working directory for sessions (default current directory)

認証情報はユーザー名とパスワードを引数で渡す、authorized_keysを使うなどですね。

  <auth> must be set to one of:
  1. a username and password string separated by a colon ("myuser:mypass")
  2. a path to an ssh authorized keys file ("~/.ssh/authorized_keys")
  3. an authorized github user ("github.com/myuser") public keys from .keys
  4. "none" to disable client authentication :WARNING: very insecure

認証自体を無効にできるようですが、まあ使わないでしょう。

ユーザー名とパスワードを指定して、起動してみましょう。

$ ./sshd-lite_1.31.0_linux_amd64 sample-user:password
3:55:08PM 20/3/2026  INFO Private key loaded
3:55:08PM 20/3/2026  INFO Public Key: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDdMINVCqOJBADsgDmK+gdkaU/nqYTWY4VcCQfcSUi+q00I/ZsdJpfMBE3kP7Jwdkz13BsR2IQL4yHlpW63x/ivCq+U9p4BuXVtKYzUQHhwmnIMvpTRIMkCEsQvfmPu37gsfCa9TuhH28nHSS6QXvhS833pPaojjwA8H9WLsykMqytaCXcJmyuvc53c1QyqNaDoG2jAZGGI6FA0kYVVmfJQKRecchc4DMlLt4KA/aF0f11lHWFrcG82ua30CUmFU/wRawYUAQ8/JSGpe1+1kwgAeHZoOLXHCFHkQ3/MzXuZH1FhOEk5pMPu/f8WUy2HnlFyJ+/nEO4s0oWYV0gsIMRJ
3:55:08PM 20/3/2026  INFO Fingerprint: SHA256:jDVtlpNg06uJk8h0C+2CISxFDaniN7XgZ3gWhpcncqs
3:55:08PM 20/3/2026  INFO Authentication enabled (user 'sample-user')
3:55:08PM 20/3/2026  INFO Listening on [::]:2200...

接続してみます。

$ ssh sample-user@[接続先のサーバー] -p 2200
The authenticity of host '[接続先のサーバー]:2200 ([接続先のサーバー]:2200)' can't be established.
RSA key fingerprint is SHA256:NUvBZ2iwBjG58VvDbmGX5kKl6jOH+/0oUo4v4LMQ4nk.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '[接続先のサーバー]:2200' (RSA) to the list of known hosts.
sample-user@接続先のサーバー's password:
$ 

ログインできました。

ログインできましたが、認証したユーザーとOSのユーザーには関係がないのでログインした後にBashプロンプトに
表示されるユーザー名とは合いません。最初はちょっとビックリしますが、冷静に考えるとそれはそうですね、と。

割とあっさり使えました。よさそうです。

ところで、curl+bashでのインストール方法も試してみましたが、管理者権限を持つユーザーで実行することを前提に
しているようです。

$ curl https://i.jpillora.com/sshd-lite! | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  7601    0  7601    0     0   3739      0 --:--:--  0:00:02 --:--:--  3740
Installing jpillora/sshd-lite latest (linux/amd64).....
######################################################################## 100.0%
============
Error: mv failed (mv: './sshd-lite' から '/usr/local/bin/sshd-lite' へ移動できません: 許可がありません)

こうしないとインストールできません。

$ curl https://i.jpillora.com/sshd-lite! | sudo bash

これならバイナリーを直接ダウンロードする、でいいかも…と思いました。

おわりに

シングルバイナリーで簡易的なSSHサーバーを動かせるsshd-liteを使ってみました。

細かく見ていると気になるところがあるのですが、今回の目的には十分です。覚えておきましょう。




以上の内容はhttps://kazuhira-r.hatenablog.com/entry/2026/03/20/160714より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14