0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

windowsでchmodができない問題

Posted at

はじめに

AWSのEC2を用いてwebサイトを作成しようと思い、EC2サーバ(インスタンス)とローカルのSSH接続を行っていた。すると以下のような警告が出た(https://qiita.com/sekkenn1102/items/3f156db39224ae2023f1 から引用)。

The authenticity of host 'ec2-XX-XXX-XXX-XXX.ap-northeast-1.compute.amazonaws.com (XX.XXX.XXX.XXX)' can't be established.
ECDSA key fingerprint is SHA256:5vDb7b5ozqxJ0FbDv9Qao4LYSd5a+Do5p6Ay6/ZNyV0.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'ec2-XX-XXX-XXX-XXX.ap-northeast-1.compute.amazonaws.com,XX.XXX.XXX.XXX' (ECDSA) to the list of known hosts.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions for 'web-site.pem' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "web-site.pem": bad permissions
ec2-user@ec2-XX-XXX-XXX-XXX.ap-northeast-1.compute.amazonaws.com: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).

内容はSSH接続に使う秘密鍵の権限がガバガバ過ぎるから、ほかの人からのアクセスできないようにしてくれというものだった。

やること

権限を自分だけにする。SYSTEMやadministratorの権限を削除する。

解決策

継承を無効化する

PS C:\Users\ユーザ名\.ssh> icacls.exe $path /inheritance:r
処理ファイル: web-app-test-key.pem
1 個のファイルが正常に処理されました。0 個のファイルを処理できませんでした

すべてのユーザの権限を削除

PS C:\Users\ユーザ名\.ssh> icacls.exe $path /remove *
0 個のファイルが正常に処理されました。0 個のファイルを処理できませんでした

現在のユーザ(自分)に読み取り権限を付与

PS C:\Users\ユーザ名\.ssh> icacls.exe $path /grant:r "$($env:USERNAME):(R)"
処理ファイル: web-app-test-key.pem
1 個のファイルが正常に処理されました。0 個のファイルを処理できませんでした

権限の確認

PS C:\Users\ユーザ名\.ssh> icacls.exe $path
web-app-test-key.pem DESKTOP-EOCTDAN\ats_1:(R)

最後に

0
1
0

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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?