0
I have sudo permissions and I'm trying to unpack a file with cpio command.
However, because of the path properties I get permission denied when I try to do it.

$ id
uid=4777(testuser) gid=100(users) groups=100(users),1008(otherwheel)

The home path has 700 permission:
$ sudo ls -ld /home/uadmin/
[sudo] password for testuser:

drwx------. 16 uadmin uadmin 4096 dic 1 15:26 /home/uadmin/

The file has 775 permission:
$ sudo ls -l /home/uadmin/RH7HOTFIX/INSTALL
[sudo] password for testuser:

-rw-rw-r-- 1 root root 163840 abr 28 2016 /home/uadmin/RH7HOTFIX/INSTALL

When I try to unpack the file I get 'permission denied':
$ sudo cpio -ivcBdum install</home/uadmin/RH7HOTFIX/INSTALL

-bash: /home/uadmin/RH7HOTFIX/INSTALL: permission denied

I can´t change the path permission.
I can´t move the file because of the disk space.
I can´t use sudo -i for a new shell.

My OS is Red Hat Enterprise 7.2

Any ideas?
Thanks in advanced.
DASM
The-0m3n
  • 11
  • 2

1 Answers1

1

sudo and shell redirection is broken

Here's a good explanation and some workarounds:

Your command does not work because the redirection is performed by your shell which does not have the permission to write to [the file]. The redirection of the output is not performed by sudo.

  1. Run a shell with sudo and give the command to it by using the -c option
  2. Create a script with your commands and run that script with sudo
  3. Launch a shell with sudo -s then run your commands
  4. Use sudo tee (if you have to escape a lot when using the -c option)

7-zip

Alternately, you could unpack the archive using a program that does not require shell redirection, such as 7-zip, which should be available for RHEL 7 via rpmforge.

Here's a HowTo:

  1. Download the repo using the command given below.

sudo wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm

  1. Now install the downloaded rpm using

sudo rpm -ivh rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm

  1. Now you need to install the package

sudo yum install p7zip

  1. To unzip the file use the following command

sudo 7za x <filename>

Hydraxan14
  • 658
  • 6
  • 15
  • Thanks Hydraxan14. Creating a script worked successfully. The other options don´t work because my account is not allowed to execute /bin/bash or /bin/sh. Thanks for the help. DASM – The-0m3n Dec 21 '16 at 00:12
  • @The-0m3n Welcome! Please click on the checkmark underneath my answer to mark your question as solved. – Hydraxan14 Apr 05 '17 at 17:39