0

I'm working as user "papagolf" which is a sudo user. I created a new group "hadoop" by using

papagolf@Sierra:~$ sudo addgroup hadoop

Created a user "haduser"

papagolf@Sierra:~$ sudo adduser --ingroup hadoop haduser

I've already created ssh keys in papagolf's .ssh directory and copied the public key file into this new directory

papagolf@Sierra:~$ cp hadoop_keys.pub /home/haduser/.ssh/

Created a new file in .ssh/authorized_keys

papagolf@Sierra:~$ cd /home/haduser/.ssh/
papagolf@Sierra:/home/haduser/.ssh$ sudo touch authorized_keys

Now I wanted to copy the content of .pub file to authorized_keys but I got an error saying that the permission is denied. I wonder why it happened even when I'm a sudo user.

papagolf@Sierra:/home/haduser/.ssh$ sudo cat hadoop_keys.pub >> authorized_keys
bash: authorized_keys: Permission denied

Now I tried this and it was successful

papagolf@Sierra:/home/haduser/.ssh$ sudo -i
root@Sierra:/home/haduser/.ssh# cat hadoop_keys.pub >> authorized_keys

What's the difference? Why did the error occur?

7_R3X
  • 1,174
  • 2
    duplicate. http://unix.stackexchange.com/questions/1416/redirecting-stdout-to-a-file-you-dont-have-write-permission-on – Ipor Sircer Sep 19 '16 at 09:23

1 Answers1

1

In question mentioned by Ipor Sircer you will find how to achieve your goal.

I will just add short explanation. Stream redirection (>> in this case) is done by a shell, not a process run with sudo, therefore your shell (papagolf's shell) still has no right to write to other user directory. That's why people use tee or sed to do it.

Kalavan
  • 666