It is required that your private key files are NOT accessible by others

When connecting to a server, you'll usually need some kind of authentication to log in, whether it be a username/password or key file. Usernames and passwords are pretty straight-forward, but things can get a bit more confusing when it comes to using private keys. Not only do you need to run SSH with extra commands, but it turns out that the key file itself needs to have certain properties.

Have you run in to the warning message below, and don't know how to fix it?

Warning: Permanently added '192.168.1.1' (RSA) to the list of known hosts.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for '/path/to/my/key.pem' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
bad permissions: ignore key: /path/to/my/key.pem
Permission denied (publickey).

It's a common error to see when trying to log in to a server via SSH and a key file, and luckily it has a relatively easy fix. But before we get to that, let's get some background on why this error shows up.

Why am I seeing this Error?

What happened is the key you're trying to use (key.pem in the example above) is too accessible to users on the system.

This is a bad thing because then you're not the only one able to use the key, which defeats the purpose. Private keys should only be accessible to one user.

For example, if an attacker somehow gains access to any of the accounts on your system, then they'd be able access the key, as opposed to having to get access to your account specifically. This gives them too many opportunities to get to the private key.

How can I fix it?

Like I said earlier, this is an easy fix. Just run:

$ sudo chmod 600 /path/to/my/key.pem

Keep in mind that if you keep all of your keys in the ~/.ssh directory (or any other directory, really), you may need to adjust the permissions for that directory as well. In that case, use this:

$ sudo chmod 755 ~/.ssh

And that's all there is to it. Now you should be able to use your key with no problems.

I get the following error from ssh:

Permissions 0777 for '/Users/username/.ssh/id_rsa' are too open.
It is recommended that your private key files are NOT accessible by others.
This private key will be ignored.

What permissions should I give to the id_rsa file?

It is required that your private key files are NOT accessible by others

Mateen Ulhaq

22.2k16 gold badges86 silver badges127 bronze badges

asked Feb 14, 2012 at 2:02

Yannick SchallYannick Schall

30.2k6 gold badges29 silver badges42 bronze badges

6

The keys need to be read-writable only by you:

chmod 600 ~/.ssh/id_rsa

Alternatively, the keys can be only readable by you (this also blocks your write access):

chmod 400 ~/.ssh/id_rsa

600 appears to be better in most cases, because you don't need to change file permissions later to edit it. (See the comments for more nuances)

The relevant portion from the manpage (man ssh)

 ~/.ssh/id_rsa
         Contains the private key for authentication.  These files contain sensitive 
         data and should be readable by the user but not
         accessible by others (read/write/execute).  ssh will simply ignore a private 
         key file if it is              
         accessible by others.  It is possible to specify a
         passphrase when generating the key which will be used to encrypt the sensitive 
         part of this file using 3DES.

 ~/.ssh/identity.pub
 ~/.ssh/id_dsa.pub
 ~/.ssh/id_ecdsa.pub
 ~/.ssh/id_rsa.pub
         Contains the public key for authentication.  These files are not sensitive and 
         can (but need not) be readable by anyone.

Zain Rizvi

23k19 gold badges87 silver badges127 bronze badges

answered Feb 14, 2012 at 2:05

18

Using Cygwin in Windows 8.1, there is a command need to be run:

chgrp Users ~/.ssh/id_rsa

Then the solution posted here can be applied, 400 or 600 is OK.

chmod 600 ~/.ssh/id_rsa

Reference here

Cadoiz

1,06215 silver badges24 bronze badges

answered Apr 11, 2014 at 11:17

tanza9tanza9

1,4671 gold badge10 silver badges8 bronze badges

6

I've got the error in my windows 10 so I set permission as the following and it works.

It is required that your private key files are NOT accessible by others

In details, remove other users/groups until it has only 'SYSTEM' and 'Administrators'. Then add your windows login into it with Read permission only.

Note the id_rsa file is under the c:\users\<username> folder.

answered Dec 8, 2018 at 3:08

It is required that your private key files are NOT accessible by others

5

The locale-independent solution that works on Windows 8.1 is:

chgrp 545 ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa

GID 545 is a special ID that always refers to the 'Users' group, even if you locale uses a different word for Users.

answered Feb 21, 2015 at 15:51

It is required that your private key files are NOT accessible by others

thehousethehouse

7,6875 gold badges32 silver badges32 bronze badges

0

Windows 10 ssh into Ubuntu EC2 “permissions are too open” error on AWS

I had this issue trying to ssh into an Ubuntu EC2 instance using the .pem file from AWS.

In windows this worked when I put this key in a folder created under the .ssh folder

C:\Users\USERNAME\.ssh\private_key

To change permission settings in Windows 10 :

File Settings > Security > Advanced

Disable inheritance

Convert Inherited Permissions Into Explicit Permissions

Remove all the permission entries except for Administrators

Could then connect securely.

answered Mar 26, 2020 at 12:45

lm5050lm5050

6887 silver badges8 bronze badges

2

AFAIK the values are:

  • 700 for the hidden directory .ssh where key files are located

  • 600 for the keyfile id_rsa

Cadoiz

1,06215 silver badges24 bronze badges

answered Nov 13, 2014 at 7:57

It is required that your private key files are NOT accessible by others

ajaaskelajaaskel

1,57911 silver badges12 bronze badges

0

0600 is what mine is set at (and it's working)

answered Feb 14, 2012 at 2:04

Devin CeartasDevin Ceartas

4,7211 gold badge20 silver badges33 bronze badges

0

I have got a similar issue when i was trying to login to remote ftp server using public keys.
To solve this issue I have done the following process:

  • First find the location of the public keys, because when you try to login to ftp, this public key is used.
  • Alternatively, you can create a key and set that key's permissions to 600.
  • Make sure you are in the correct location and perform this command:
chmod 600 id_rsa

answered May 26, 2020 at 13:50

1

On Windows 10, cygwin's chmod and chgrp weren't enough for me. I had to

  • right click on the file
  • -> Properties
  • -> Security (tab)
  • and remove all users and groups except for my active user.

Cadoiz

1,06215 silver badges24 bronze badges

answered Jul 21, 2018 at 5:39

It is required that your private key files are NOT accessible by others

Jared BeachJared Beach

2,23630 silver badges35 bronze badges

2

provide 400 permission, execute below command

chmod 400 /Users/username/.ssh/id_rsa

It is required that your private key files are NOT accessible by others

answered Aug 28, 2018 at 11:03

0

I got success with sudo

sudo chmod 400 pem-file.pem
sudo ssh -i pem-file.pem 

answered Mar 3, 2021 at 3:31

It is required that your private key files are NOT accessible by others

Navy FlameNavy Flame

7977 silver badges19 bronze badges

3

There is one exception to the 0x00 permissions requirement on a key. If the key is owned by root and group-owned by a group with users in it, then it can be 0440 and any user in that group can use the key.

I believe this will work with any permissions in the set 0xx0 but I haven't tested every combination with every version. I have tried 0660 with 5.3p1-84 on CentOS 6, and the group not the primary group of the user but a secondary group, and it works fine.

This would typically not be done for someone's personal key, but for a key used for automation, in a situation where you don't want the application to be able to mess with the key.

Similar rules apply to the .ssh directory restrictions.

Cadoiz

1,06215 silver badges24 bronze badges

answered Nov 13, 2013 at 17:18

syberghostsyberghost

3092 silver badges4 bronze badges

0

For windows users Only. Goto file property --> security --> advanced

  1. Disable inheritance property
  2. Convert Inherited Permissions Into Explicit Permissions.
  3. Remove all the permission entries except the Administrators.
    It is required that your private key files are NOT accessible by others

It is required that your private key files are NOT accessible by others

answered Jul 27, 2020 at 4:50

It is required that your private key files are NOT accessible by others

VasuVasu

4415 silver badges7 bronze badges

0

This is what worked for me (on mac)

sudo chmod 600 path_to_your_key.pem 

then :

ssh -i path_to_your_key user@server_ip

Hope it help

answered Jan 22, 2019 at 12:14

It is required that your private key files are NOT accessible by others

lansanalsmlansanalsm

3292 silver badges9 bronze badges

0

For me (using the Ubuntu Subsystem for Windows) the error message changed to:

 Permissions 0555 for 'key.pem' are too open

after using chmod 400. It turns out that using root as a default user was the reason.

Change this using the cmd:

 ubuntu config --default-user your_username

answered Dec 2, 2018 at 4:30

It is required that your private key files are NOT accessible by others

In case you are using WSL on windows

The most simple answer is to just type: sudo ssh -i keyfile.pem <user>@ip

without changing the file permissions. The reason why this happens? Another resource

You can't modify the permissions of files on Windows's filesystem using chmod on Bash on Ubuntu on Windows. You'll have to copy the private key to your WSL home directory (~) and do it there.


On the other hand, sudo should never be utilized with ssh. The reason why issuing with sudo works is that it's now likely being executed as root, and this is not the correct way to do this and is a massive security risk, as Allowing for anything other the 600/400 permissions defeats the purpose of utilizing an SSH key, compromising the security of the key.

The best way to do that is by copying the file to $HOME/.ssh:

cp keyfile.pem ~/.ssh

Doing sudo chmod 400 keyfile.pem to it.

Then ssh -i keyfile.pem <user>@ip.

answered Nov 15, 2021 at 9:22

Mostafa WaelMostafa Wael

1,6521 gold badge12 silver badges16 bronze badges

what worked for me

chgrp Users FOLDER

chmod 600 FOLDER

answered Mar 26, 2014 at 22:54

Jerome AnsiaJerome Ansia

6,74410 gold badges49 silver badges99 bronze badges

3

I got same issue after migration from another mac. And it blocked to connect github by my key.

I reset permission as below and it works well now.

chmod 700 ~/.ssh     # (drwx------)
cd ~/.ssh            
chmod 644 *.pub      # (-rw-r--r--)
chmod 600 id_rsa     # (-rw-------)

It is required that your private key files are NOT accessible by others

answered Jul 28, 2019 at 3:59

It is required that your private key files are NOT accessible by others

Jeff Gu KangJeff Gu Kang

4,4912 gold badges32 silver badges43 bronze badges

1

As people have said, in Windows, I just dropped my .pem file in C:\Users\[user]\.ssh\ and that solved it. Although you can do chmod and other command line options from a bash or powershell prompt that didn't work. I didn't change rsa or anything else. Then when running the connection you have to put the path to the pem file in the .ssh folder:

ssh -i "C:\Users\[user]\.ssh\ubuntukp01.pem" ubuntu@ec[ipaddress].us-west-2.compute.amazonaws.com

answered Jun 25, 2020 at 12:22

Win SwarrWin Swarr

691 silver badge1 bronze badge

0

700  folder
644  id_rsa.pub

this works for me.

answered Apr 9, 2021 at 9:47

It is required that your private key files are NOT accessible by others

B.KingsunB.Kingsun

1941 silver badge10 bronze badges

I keep all my own certificates and keys in one directory, and this works for tools like PuTTY, but I got this too open error message from the scp command. I discovered that Windows already maintains a C:\users\ACCOUNTNAME\.ssh folder having the proper access rights for storing SSH keys. So long as you keep the contents backed up (Windows sometimes deletes it during updates), or create your own folder for ssh keys in your user folder, this will work fine, as only you and the administrators have access to that parent folder.

Be very careful about changing access rights on Windows folders. I did this, and once a day Windows is scanning, reading, and writing all the files on my C: drive, a process that slows the computer for many minutes.

answered Dec 29, 2020 at 19:52

0

Interesting message here. Operating Systems are smart enough to deny remote connections if your private key is too open. It understands the risk where permissions for id_rsa is wide open (read, is editable by anyone).

{One may change your lock first and then open it with the keys he already has}

cd ~/.ssh
chmod 400 id_rsa

While working on the multiple servers (non-production), most of us feel need to connect remote server with ssh. A good idea is to have a piece of application level code (may be java using jsch) to create ssh trusts between servers. This way connection will be password-less. Incase, perl is installed - one may use net ssh module too.

answered May 13, 2015 at 7:35

The other trick is to do that on the downloads folder. After you download the private key from AWS EC2 instance, the file will be in this folder,then simply type the command

ssh-keygen -y -f myprivateKey.pem > mypublicKey.pub

answered Aug 25, 2020 at 14:48

I am using Windows 10 and trying to connect to EC2 instance via SSH. Rather than using Cygwin for Windows, try using Git Bash. After doing chmod 400 for key I am able to SSH into the EC2 instance, but the same is not working for me from Cygwin. Windows treats the .pem file as coming from internet and blocks it, even disabling inheritance doesn't work.

I converted the file to .ppk format and it's working fine from PuTTY also, but it's not working from Cygwin.

It is required that your private key files are NOT accessible by others

karel

4,85342 gold badges42 silver badges48 bronze badges

answered Apr 3, 2021 at 16:25

AshuAshu

5857 silver badges16 bronze badges

1

In my case the issue was a whitespace too much.

ssh -i mykey.pem  

but

ssh -i mykey.pem 

worked fine. The problem is that the whitespace is taken as part of the username.

answered Mar 19, 2021 at 13:00

coorassecoorasse

4,9981 gold badge31 silver badges43 bronze badges

I have came across with this error while I was playing with Ansible. I have changed the permissions of the private key to 600 in order to solve this problem. And it worked!

chmod 600 .vagrant/machines/default/virtualbox/private_key

answered Apr 2, 2018 at 15:53

It is required that your private key files are NOT accessible by others

vildhjartavildhjarta

5342 gold badges5 silver badges15 bronze badges

For Windows 10 this is what I've found works for me:

  1. Move your key to the Linux file system: mv ~/.ssh /home/{username}
  2. Set the permission on that key: chmod 700 /home/{username}/.ssh/id_rsa
  3. Create a symbolic link to the key: ln -s /home/{username}/.ssh ~/.ssh

This happens if you have set your home directory (~) to be stored in Windows instead of Linux (under /mnt/ vs /home/).

answered Jul 26, 2020 at 21:06

theEpsilontheEpsilon

1,62216 silver badges27 bronze badges

I was getting this issue on WSL on Windows while connecting to AWS instance. My issue got resolved by switching to classic Command prompt. You can try switching to a different terminal interface and see if that helps.

answered Feb 19, 2021 at 19:06

It is required that your private key files are NOT accessible by others

LeenaLeena

5411 gold badge10 silver badges19 bronze badges

I tried 600 level of permission for my private key and it worked for me.

chmod 600 privateKey 
[dev]$ ssh -i privateKey user@ip

On the other hand,

chmod 755 privateKey 
[dev]$ ssh -i privateKey user@ip

was giving below issue:

Permissions 0755 for 'privateKey' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "privateKey": bad permissions

answered Feb 14, 2019 at 8:41

PuTTY can do the work on windows 10. It generates a public key using a private key as input.

  1. Download PuTTY
  2. Install PuTTY. Two applications come upon the installation: putty config, putty key gen
  3. Launch puttyGen
  4. Click load and select a private key file. Please note, you need to rename your private key file with .ppk extension, e.g. private-key.ppk

It is required that your private key files are NOT accessible by others

It is required that your private key files are NOT accessible by others

Henry Ecker

32.6k17 gold badges30 silver badges50 bronze badges

answered Aug 25, 2020 at 14:37

1

What permissions are needed for private key?

The private key file on your local workstation (client-side) should have permissions set to 600 , and the . ssh directory should have the permissions set to 700 .

How do I fix unprotected private key file?

In order to solve the "Warning: Unprotected Private Key File" error in AWS EC2, update the permissions of the private key file to only allow read access from the current user, e.g. chmod 600 ec2-private-key. pem . Open your terminal in the directory where your private key is located and run the chmod command. Copied!

Which of the following command is used to set the permissions of your private key file?

To change file and directory permissions, use the command chmod (change mode). The owner of a file can change the permissions for user ( u ), group ( g ), or others ( o ) by adding ( + ) or subtracting ( - ) the read, write, and execute permissions.