私はこれを行う方法をいくつか試しましたが、最初に働いたのは ssh-copy-id
#By default this puts keyfile pair in ~/.ssh/id_rsa & ~/.ssh/id_rsa.pub :
ssh-keygen.exe -t rsa -b 2048
ssh-copy-id -i ~/.ssh/id_rsa.pub $remoteuser@$remotehost
# I'm not sure if these two chmod lines are needed on windows but
# typically ssh refuses to use a private key file
# if it is less-well protected than this:
chmod 700 ~/.ssh
chmod 640 ~/.ssh/id_rsa
ssh
ツールを入手する最も簡単な方法は、git for Windowsをインストールすることです。
git-installed bash shellから上記のコマンドを実行しました。PowerShellからssh-copy-idを実行するとどうにか機能しなかったため、このPowerShellスクリプトで終了しました
Param(
[Parameter()][string]$keyfile="id_rsa",
[Parameter()][string]$remotehost,
[Parameter()][string]$remoteuser
)
write-host "# ---------------------------------------------------------------------------------#"
write-host "# Create an RSA public/private key pair, and copy the public key to remote server #"
write-host "# #"
write-host "# https://superuser.com/questions/96051 #"
write-host "# ssh-from-windows-to-linux-without-entering-a-password/1194805#1194805 #"
write-host "# #"
write-host "# ---------------------------------------------------------------------------------#"
write-host "Keyfile pair will be saved at : ~/.ssh/$keyfile, ~/.ssh/$keyfile.pub"
write-host "And copied to $remoteuser@$remotehost"
write-host ""
write-host "You will need a password for the copy operation."
write-host ""
if( -not $(ls ~/.ssh) ) { mkdir ~/.ssh }
$sshdir=$(get-item ~/.ssh/).Fullname
#By default this puts keyfile pair in ~/.ssh/id_rsa & ~/.ssh/id_rsa.pub :
ssh-keygen.exe -t rsa -b 2048 -f "$sshdir$keyfile"
bash -c "ssh-copy-id -i ~/.ssh/$keyfile.pub $remoteuser@$remotehost"
# I'm not sure if these two chmod lines work on windows but
# typically ssh refuses to use a private key file
# if it is less-well protected than this:
chmod.exe 700 $sshdir
chmod.exe 640 "$sshdir$keyfile"