314 文字
2 分
Windows で ssh-copy-idを使う方法【WSL】

はじめに#

Windowsからsshの公開鍵をサーバーに転送するのを手作業でやっていませんか?Windowsの PowerShell で ssh-copy-id を使いたくないですか? 本記事では Windowsで手軽に ssh-copy-id を使用する方法 を解説します。 WSLを利用します。


前提条件#

  • WindowsにWSLがインストールされている
  • 接続先サーバーに ssh user@host で到達できる

手順#

1. WSLを起動する#

wsl

以降はWSL内で実行します。


2. SSH鍵を用意する#

mkdir -p ~/.ssh
chmod 700 ~/.ssh

新規作成する場合#

ssh-keygen -t ed25519 -f ~/.ssh/key
  • 秘密鍵: ~/.ssh/key
  • 公開鍵: ~/.ssh/key.pub

Windowsで作成済みの鍵を使う場合#

Windows側の鍵をWSLにコピーします。

cp /mnt/c/Users/ユーザー名/.ssh/id_ed25519 ~/.ssh/key
cp /mnt/c/Users/ユーザー名/.ssh/id_ed25519.pub ~/.ssh/key.pub
chmod 600 ~/.ssh/key

/mnt/c/Users/ユーザー名/ はWindows側のホームディレクトリです。鍵のファイル名は環境に合わせて変更してください。


3. 公開鍵をサーバーに登録する#

ssh-copy-id -i ~/.ssh/key.pub user@host

初回はパスワード入力が必要です。


4. 接続を確認する#

ssh -i ~/.ssh/key user@host

パスワードなしで接続できれば完了です。


関連記事#

毎回 -i オプションを省略したい場合は、SSH configを設定してください。
SSH configを設定する方法

Windows で ssh-copy-idを使う方法【WSL】
https://naonao-na.com/posts/ssh-copy-id-windows/
作者
[object Object]
公開日
2025-12-10
ライセンス
CC BY-NC-SA 4.0