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

WindowsでOpehSSHサーバーを立ち上げる

3
Last updated at Posted at 2020-04-12

概要

chocolateyをつかってWindowsにSSHサーバーを立てた時のメモ。
最近のWindows10なんかは標準で入っていたりするらしいので需要ないかな。

書いていないこと

  • chocolatey導入手順
  • 公開鍵の配置手順の詳細

導入するもの

環境

  • Windows Server 2012R2
  • chocolatey v0.10.15

インストール

PowerShellを管理者として立ち上げて、以下のコマンド実施します

管理者:WindowsPowerShell
choco install openssh -params '"/SSHServerFeature"' -confirm

インストールが完了したら、path変更を反映させるために別のPowerShellを開き、以下のコマンド実行します。

管理者:WindowsPowerShell
ssh Administrator@localhost

パスワードはWindowsログイン用のものと同じ。エラーなくログインできればインストール完了です。

  • Administratorでログインできることはこの際おいときましょう
  • Windows Server 2012R2上でsshコマンドを実行しとたんpowershellの挙動がおかしくなったのですが、
    サーバとしての挙動は問題なさそうなのでこれもいったんおいておきます。
    (フォントがラスターフォントになるとか、powershellが急に落ちるとか)

インストール時に設定するパラメーターについて

/SSHServerFeature

Windowsサービスとしてインストールする場合に指定するパラメータです。
sshdという名前のサービスが追加されます。
ポート番号を22以外に変更したい場合は
-params '"/SSHServerFeature /SSHServerPort:3834"'
とかするといいようです

/KeyBasedAuthenticationFeature は指定不要

たまに /KeyBasedAuthenticationFeature をつけてインストールしている記事を見かけますが、今は不要になってるぽいです。

RETIRED: -params '"/KeyBasedAuthenticationFeature"'
NO LONGER NECESSARY - KeyBasedAuthentiation is always configured
if the /SSHServerFeature switch is used.

※ これがこの記事を書きたかった一番の理由だったり:yum:


設定

キーペア設定

せっかくなんで、ed25519を使ったキーペアを作ってこれまでの鍵を置き換えました。
それまではRSA 2048bit使ってたのですが、あと10年ぐらいで非推奨になっちゃうので。

キーペア作成
ssh-keygen -t ed25519 -C 'COMMENT'

2つのファイルが作成されるのでそれぞれ所定の場所に格納します

  • 公開鍵: id_ed25519.pub → 内容をサーバの ~\.ssh\authorized_keys ファイルに追加
  • 秘密鍵: id_ed25519 → クライアントの ~\.ssh\id_ed25519 として格納
    • Windowsの~/.sshフォルダはC:\Users\{ユーザ名}\.ssh

sshd_config 設定

パスワードによるログイン禁止

  • ssh 設定ファイル: C:\ProgramData\ssh\sshd_config
sshd_configの変更箇所
# To disable tunneled clear text passwords, change to no here!
- #PasswordAuthentication yes
+ PasswordAuthentication no
# PermitEmptyPasswords no

変更後はsshdサービスを再起動が必要。以下のコマンドで実施。

管理者:WindowsPowerShell
Restart-Service sshd

補足

Universal Installerって

ここまで書いてなんですが、わざわざChocolately使わなくても同じパッケージがインストールできるようです。

This package is actually a universal installer that can install in any scenario - including without Chocolatey.

詳細はこちら
余裕ができたら他のインストール方法調べてみます。

おまけ:chocolateyのアップデート方法

管理者のPowerShellで以下実行

管理者:WindowsPowerShell
choco upgrade chocolatey
  1. 手順通り導入するとbetaは導入されないことに気づいたので訂正( 2020.9.21) ↩

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