daily-code icon indicating copy to clipboard operation
daily-code copied to clipboard

AWS EC2 : Alternate choice for "chmod" for windows

Open kmr-rohit opened this issue 1 year ago • 2 comments

Issue :- In AWS Deploying tracks, after getting .pem file , when we try to connect to virtual machine using ssh we get permissions denied.

For mac , it is easy to use chmod , but windows doesn't support "chmod"

image

Solution : In windows 11 powershell I did run the below commands which will be equivalent to chmod

Note: first change the DIR to the folder where you have your .pem file named as key.pem

icacls.exe key.pem /reset icacls.exe key.pem /grant:r "$($env:username):(r)" icacls.exe key.pem /inheritance:r

@hkirat , please add the following code snippet to the track deck.

kmr-rohit avatar Feb 24 '24 19:02 kmr-rohit

@kmr-rohit in windows you have to remove access of the file from everyone in advanced properties of this file and manually add who can acces it .

Basant-Chahar-2003 avatar Mar 25 '24 17:03 Basant-Chahar-2003

$path = "filenamegoeshere" Reset to remove explict permissions icacls.exe $path /reset Give current user explicit read-permission icacls.exe $path /GRANT:R "$($env:USERNAME):(R)" Disable inheritance and remove inherited permissions icacls.exe $path /inheritance:r

--source-- https://gist.github.com/jaskiratr/cfacb332bfdff2f63f535db7efb6df93 https://stackoverflow.com/questions/43312953/using-icacls-to-set-file-permission-to-read-only/43317244#43317244

newbincoding avatar Apr 10 '24 23:04 newbincoding

I had the same issue. The solution is simple, just get a linux distro in WSL2.

But even if you manage to locate your .pem file using WSL2 it won't be able to change your file permission using chmod, because your .pem file is part of Windows file system and not Linux file system. Reference: https://www.reddit.com/r/bashonubuntuonwindows/comments/vzyne4/chmod_not_totally_working_in_wsl/

To solve the issue you need to copy your .pem file from Windows file system to Linux file system. You can do that by copying your .pem and pasting it in your WSL2 Linux's location, which you can easily locate by typing explorer.exe . in your WSL2 terminal. Now use that .pem file to change permissions using chmod , and it'll work fine.

sid-sg avatar Jun 25 '24 09:06 sid-sg