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 3 years have passed since last update.

[Win10] PowerShellのSSHで公開鍵(public key)のPermission対策

Last updated at Posted at 2021-10-27

こういうエラーをどう対応するか?
Windowsではchown,chmodとかできない。でもcygwinは嫌いな人向け。

CurrentDir> ssh hoge
The authenticity of host 'hoge' can't be established.
ECDSA key fingerprint is SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.
Are you sure you want to continue connecting (yes/no)? yes
Failed to add the host to the list of known hosts (C:\\Users\\sugimura/.ssh/known_hosts).
sugimura@hoge: Permission denied (publickey).

Windowsはuser直下フォルダはadminもアクセス可能になっていて、user onlyのpermissionとしてDocumentsを使うみたい。
したがって下記のようにconfigとkeyの格納フォルダを分けておくとうまくいく。
すごく残念

  • sshのconfigファイルは %homepath%.ssh フォルダに置いておく
  • sshのkeyファイルは %homepath%\Documents.ssh フォルダに置いておく
  • configファイルでのIdentityFileの指定は ~/Documents/.ssh/ とする

なお、configファイル内はpath separatorが\でも/でもいいみたい。
mac, linuxとの互換性(Documents/を消すだけなので修正が容易)を考えて"/"を使ってる。

過去情報

コマンドで頑張ってWindows内部のPermissionを制御する方法

こんな感じのコマンドで行けます。****は自分のファイル名に置き換えてください。

  • コマンドプロンプトを管理者モードで起動
    • コマンドプロンプト起動時に,右クリックで管理者で実行すればよい。
anyDir> cd %USERPROFILE%
CurrentDir> takeown /F .ssh /A
CurrentDir> takeown /F .ssh
CurrentDir> icacls .ssh /grant Administrators:F

anyDir> cd ~/.ssh
CurrentDir> takeown /F <publickey> /A
CurrentDir> takeown /F <publickey>
CurrentDir> icacls <publickey> /grant Administrators:F
0
0
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
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?