I have a file in a subdirectory of /etc/ which I would like to copy, I can run this file as a regular user, however when I run

cp /etc/subdir/desired_file .

I am refused permission. However I can execute this file without superuser permissions. Is there a way for me to copy this file into another directory?

edit: without changing file permissions

  • ls -l /etc/file gives you -rws--x--x 1 root root suid & user's executable bit enabled (lowercase s) - the bits rwsr-x---x are set. – Dipankar Nalui Apr 4 '18 at 9:18
  • Only chmod can change this. And root user has that permission. So normal user will not be able to do anything. read here unix.stackexchange.com/questions/79395/… – Dipankar Nalui Apr 4 '18 at 9:21
  • Do you have write permission in the target directory? – Kusalananda Apr 4 '18 at 9:26
  • can you post the output of 'll filename' command. – erTugRul Apr 4 '18 at 9:36
  • 1
    You might think that you could start executing the program and then use a utility to copy the process memory to a file. But I believe that when you're executing a read-restricted binary, memory-reading utilities are blocked as well. – Barmar Apr 4 '18 at 19:26

There could be two scenarios here:

  1. Either you lack read permission on desired_file. You might be having execute permission on the file but to view or copy the file, read permission is required.

  2. Or you lack write permissions on the destination directory.

Please go through https://www.tutorialspoint.com/unix/unix-file-permission.htm . It will help you know of unix permissions.

The owner can grant permissions using chmod command.

  • 1
    Yes I lack read and write permissions, however given that I am capable of executing the program, is there any way to get the data of the executable and place that somewhere else. I.e. indirectly copy the program? – Pale Apr 4 '18 at 8:26
  • You can ask the owner to grant permission or impersonate the group or owner id to modify permissions. It is not possible to read a file's content with execute permission only. – Nik Apr 4 '18 at 8:31
  • You can run the below command to add the read permissions. But, this will require one time access to superuser --> chmod 755 /etc/subdir/desired_file – Nik Apr 4 '18 at 8:34
  • 1
    Yes I know about chmod, I should have made it clear in my question without gaining super user permissions. – Pale Apr 4 '18 at 8:46
  • 1
    If you're thinking about using ptrace() (eg: gdb, strace), forget it: if the "text" file is not readable you get an EPERM error. – A.B Apr 4 '18 at 12:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.