2

I am following these steps in setting up a public/private key set on my server:

Modify the permissions on the public key by entering the following commands, one by one, on your Linode. Replace example_user with your username.

chown -R example_user:example_user .ssh
chmod 700 .ssh
chmod 600 .ssh/authorized_keys

But when i do the first line

chown -R david:david .ssh

I get the error message:

 changing ownership of '.ssh/authorized_keys': Operation not permitted

I have followed the steps of the guide, except the fact I am using windows so I had to use windows scr to upload the public key rather than the unix command line.

Here are the file information bits:

  File: `.ssh/authorized_keys'
  Size: 294             Blocks: 8          IO Block: 4096   regular file
Device: EDITED OUT    Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2013-03-17 16:32:06.000000000 +0000
Modify: 2013-03-17 16:32:06.000000000 +0000
Change: 2013-03-17 19:06:14.000000000 +0000
3
  • 2
    What type of filesystem is your .ssh folder on? Does the filesystem support ownership? Some don't, (e.g. fat, some network fs, etc).
    – Zoredache
    Mar 17, 2013 at 19:37
  • Why use the root account to administer the files of an ordinary user? If you instead use the david account for file transfer as well as login there will be no need to chown any files. Jan 13, 2015 at 7:50
  • 1
    File owner is root: Uid: ( 0/ root) Gid: ( 0/ root) Try to do sudo chmod as already mentioned.
    – Dirge
    Jan 13, 2015 at 8:54

4 Answers 4

3

It looks like you don't have permissions to change ownership of that file. My guess, whatever filesystem you transferred the file from has different kind of privileges that didn't get transferred correctly, and just ended up owning the document to root. Try the same chown command again with sudo (as in, sudo chown -R david:david /path/to/.ssh). Whenever using a command with sudo, it is best practice to use the absolute path (e.g., /home/david/.ssh) instead of the relative path ( ./.ssh ).

2
  • I tried that and it says, sudo command not found. Any ideas? :)
    – david
    Mar 17, 2013 at 19:45
  • Become root using su -, then try the command again.
    – Scrivener
    Mar 17, 2013 at 21:47
1

For my case:
I tried
lsattr authorized_keys
and it results
-----a-------e-- authorized_keys.
The a here means append-only.

Use chattr -a authorized_keys to remove the a to make it normal.

1
  • 1
    This answer ultimately led me to my resolution, lsattr indicated 'i' which was immutable, and the file couldn't be changed. I had to run chattr -i authorized_keys in order to be able to make it mutable again. Thanks! Sep 23, 2023 at 14:37
0

su -c "chown david:david ~david/.ssh/authorized_keys"

at this point you will be asked the password for root and hopefully you know the root password for this machine. Otherwise, you have steep hill to climb ahead of you, in the lack of sudo.

0

A.D.2020 - I had similar issue with changing permissions and ownership of .ssh I couldn't push my rsa key to github.

With a little help of previous answers I sorted it out:

sudo chown -R user:user .ssh | chmod 700 .ssh | chmod 600 /home/user/.ssh/id_rsa.pub

After that:

~/.ssh -ls -la

git push -u origin master

and it's works :)

Not the answer you're looking for? Browse other questions tagged .