openssh windows bad owner or permissions

61,206

Solution 1

This started popping up immediately after I created another user with Administrator privileges, and that account began inheriting access to my .ssh folder.

You do not need to change your permissions whatsoever.

Just go to .ssh, right-click Properties, Security Tab, Advanced. DISABLE INHERITANCE, then click on the Administrator user (the one that is not you) and Remove them. Apply. Done.

Solution 2

Changing the ssh client from C:\Windows\System32\OpenSSH\ssh.exe to C:\Program Files\Git\usr\bin\ssh.exe worked for me.

Solution 3

Just got same issue after re-install windows. And easily fixed just by changing the file permissions to

.ssh-config file permissions

SYSTEM & Administrators - Full Control
[your username] - Modify & as Owner

Note:

Solution 4

For those still struggling with this, check this out: https://github.com/PowerShell/openssh-portable/pull/418. This was the case for me. It turns out that your computer should be named differently from your username... 🤷‍♂️ It will probably be fixed soon in future updates, because fix got into commit.

So again: if your computer name is the same as your username and you still haven't fixed this issue with permissions dialog, then probably renaming your computer could help.

Solution 5

I'm not sure what version of Windows you're running, but since this is recent I'd guess Windows 10. I recently found out that an OpenSSH client is installed by default as of the April 2018 update. I then found I had two instances of OpenSSH: the one I installed myself and the one Windows gave me. Uninstalling the one I had installed caused the error message you describe.

The solution that worked for me was to remove the user-installed OpenSSH as well as the C:\Users\username\.ssh folder, and let Windows 10 OpenSSH create the folder when you run the command the next time. I didn't have any configuration I was worried about losing, but if you do I'd suggest copying and pasting the contents of the files somewhere and recovering them afterwards.

Hope this helps!

Share:
61,206
gary69
Author by

gary69

Updated on July 05, 2022

Comments

  • gary69
    gary69 5 months

    I've installed openssh for windows and when I run ssh localhost I get

    Bad owner or permissions on C:\Users\gary/.ssh/config

    I've looked at these 2 questions https://superuser.com/questions/348694/bad-owner-or-permissions-error-using-cygwins-ssh-exe and https://serverfault.com/questions/253313/ssh-returns-bad-owner-or-permissions-on-ssh-config but none of the answers work for me. sshd is running as a service as the Local System user. I've run chmod 0600 C:\Users\gary\.ssh\config and chown gary C:\Users\gary\.ssh\config. I've also cleared the ACL by running setfacl -b C:\Users\gary\.ssh\config and then chmod 0600 C:\Users\gary\.ssh\config again. I've also tried changing the owner to SYSTEM and got the same error.

    I'm not sure what else to do, is there anything wrong with my setup? I also have git installed which installed mingw, I deleted ssh and sshd from my git installation so they wouldn't be on my path.

    Other commands I've run are icacls "C:\Users\gary\.ssh\config" /setowner gary chown -R gary:1049089 C:\Users\gary\.ssh

    ls -la C:\Users\gary\.ssh\config shows

    -rw-r--r-- 1 gary 1049089 229 Jan 3 14:43 'C:\Users\gary.ssh\config'

    it keeps showing this even after changing the owner to SYSTEM, but in the file properties in file explorer it shows SYSTEM as the owner

  • arberg
    arberg over 4 years
    Above worked for me, but didn't work if I replaced by username with OWNER in permission line where Fery has given it Modify permissions. Full control works for permissions.
  • neilsimp1
    neilsimp1 over 4 years
    This worked for me (OpenSSH-Win32 on Windows 10) after removing inheritance and all other permissions and adding only myself with Full Control.
  • Raúl Salinas-Monteagudo
    Raúl Salinas-Monteagudo over 3 years
    Checking the permissions given by the ssh.exe itself after removing the .ssh folder, and applying those to the rest of files, fixed the problem for me.
  • Siraj Alam
    Siraj Alam over 3 years
    It would be better if you've also told the steps.
  • weeix
    weeix over 3 years
    Thanks for the hint. I solved the issue by adding C:\Program Files\Git\usr\bin to the system variable Path and made sure that it is above (before) %SYSTEMROOT%\System32\OpenSSH. Sadly, I'm unable to use Git's ssh with Windows's ssh-agent service. I'll decrypt all my private keys then.
  • SomeGuyOnAComputer
    SomeGuyOnAComputer over 3 years
    I had to clone the repo, cd into /openssh-portable/contrib/win32/openssh and then run the above command. Much easier than configuring windows file properties and permissions.
  • vintprox
    vintprox about 3 years
    Giving full control over file to user and/or removing inheritance doesn't help. Guess I'll just change SSH client, since I have Git Bash installed :)
  • thomthom
    thomthom almost 3 years
    This appear to have been the case for me. I'd set up another User Account on the system for testing. And it had access. Once I removed that user from access to the .ssh folder it worked fine.
  • Muhammad Dyas Yaskur
    Muhammad Dyas Yaskur almost 3 years
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes
  • philistyne almost 3 years
    Just commenting to SEO this answer a bit more as it was hard to find. We were on Composer for Windows 10, version 1.9.3. This answer solved the issue of "UNPROTECTED PRIVATE KEY FILE" and " Bad owner or permissions" when trying update from our own private BitBucket repository.
  • Christophe Hubert
    Christophe Hubert over 2 years
    Please focus on answering the question without adding subjective description
  • Tin Nguyen
    Tin Nguyen over 2 years
    Thank you so much. This fixed it for me
  • Jamaxack over 2 years
    Exectly. My User name and Computer name was the same. Renaming to different names fixed the issue. Thanks
  • Derek Evermore over 2 years
    This worked for me. I am still running Win 10 1703 and am using a manually installed version of Win32-OpenSSH.
  • Grigory Kislin
    Grigory Kislin over 2 years
    Yes!! It work also under Windows 10 (done via Git Bush)
  • Liga
    Liga about 2 years
    Thank you, this solved it for me! The issue is still not fixed, I had to change my computer name.
  • phydeauxman
    phydeauxman almost 2 years
    I tried this but it did not solve the problem for me
  • Rohit Salecha
    Rohit Salecha almost 2 years
    Big thanks ! This worked for me. So below was my environment and hope someone finds this useful. - WSL 1.0 running Ubuntu 20 on a Windows 10 machine - .ssh/config file was not being read by vagrant and constantly gave permission issues. - applied the above settings and vagrant ssh worked just fine post application
  • Andy Castles almost 2 years
    This was the solution which I ended up using. The computer had the same name as the user and this meant that I didn't need to change it.
  • pabouk - Ukraine stay strong
    pabouk - Ukraine stay strong almost 2 years
    When you are disabling the inheritance you will be asked if you want to copy the current inherited access rights. Select yes and then continue by removing the other user as described above.
  • Harry
    Harry over 1 year
    I solved this by using GitBash instead of Cygwin.
  • Efren
    Efren over 1 year
    Detail update 2021. Still need to remove inheritance. Use: owner -> Full control. Administrator -> Modify. Delete any other. Note that if you open the file it may alter permissions again, depending on the software you use.
  • Simon Müller over 1 year
    This helped me. Thanks. The local Administrator was in this folder for some reason.
  • Yukihiko Shinoda
    Yukihiko Shinoda over 1 year
    Steps: [File] -> [Preferences] -> [Settings] -> Search remote.ssh.path -> Input C:\Program Files\Git\usr\bin\ssh.exe into [Remote.SSH: Path] see: code.visualstudio.com/docs/remote/…
  • Polla A. Fattah over 1 year
    How this is not marked as accepted as clearly this is solving the problem. at least it should popup as the first answer as this is the most valid one.
  • ko80 over 1 year
    Thank you so much! I had the user name equal to the computer name. Renaming the computer fixed the issue.
  • stackers
    stackers over 1 year
    "You don't need to change your permissions whatsoever, just go change the permissions"
  • Rohit Kaushal
    Rohit Kaushal about 1 year
    I had this problem I had copy pasted my old .ssh folder after reinstalling windows, thats why it was showing me this error. deleting .ssh folder and let ssh create it again worked for me.
  • mdisibio
    mdisibio about 1 year
    IT support logged into my machine as Admin and provoked this issue and this was the fix. Error came up when trying to use VSCode to ssh into remote server.
  • doghousedean 11 months
    How do I buy you a coffee/tea/beer? This has saved me from typing in a huge password every time my VPN drops! Other solutions out there that involve moving the id_rsa file around did not work for me
  • anion
    anion 11 months
    This answer may solve the issue for some users but this is not really the solution of the problem. This is more like a workaround for people who have installed git anyway.
  • andreyk2 Hohlov 9 months
    Thanks a lot! This worked for me. BWT, after I disabled INHERITANCE, and issue have fixed, I enabled in back, and all is woking.
  • R Ben R 7 months
    Not enough upvotes, I guess the terminal is a bit too scary, but this really is the better way. I will just add the known_hosts file should remain writable. ` icacls .ssh/known_hosts /grant:rw <username>:f /inheritance:r `
  • Lisa
    Lisa 7 months
    This worked for me per @YukihikoShinoda but very irritating to not understand for be able to fix the original issue.
  • yodalr
    yodalr 7 months
    yes thank you, this combined with @ala-eddine-jebali answer did the trick for me
  • Tom Malaher 5 months
    I had done this (remove inheritance, remove other users) to the .ssh directory, but the config file itself still had some other users listed. After removing those users, all is working.