1

I am trying to extract a file into /usr/local/ using

$ sudo tar -xvzf /home/vyom/Downloads/go1.19.4.linux-amd64.tar.gz -C /usr/local/
tar (child): gzip: Cannot exec: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now

But when I change the directory to which I have access to (eg - /home/vyom/abc) it works perfectly fine

$ tar -xvzf /home/vyom/Downloads/go1.19.4.linux-amd64.tar.gz -C /home/vyom/abc
go/test/typeparam/mdempsky/7.dir/b.go
go/test/typeparam/mdempsky/7.go
go/test/typeparam/mdempsky/8.dir/
go/test/typeparam/mdempsky/8.dir/a.go
go/test/typeparam/mdempsky/8.dir/b.go
go/test/typeparam/mdempsky/8.go
go/test/typeparam/mdempsky/9.go
go/test/typeparam/metrics.go
go/test/typeparam/min.go
....

gzip is also not missing

$ gzip --version
gzip 1.12
Copyright (C) 2018 Free Software Foundation, Inc.
Copyright (C) 1993 Jean-loup Gailly.
This is free software.  You may redistribute copies of it under the terms of
the GNU General Public License <https://www.gnu.org/licenses/gpl.html>.
There is NO WARRANTY, to the extent permitted by law.

Written by Jean-loup Gailly.

EDIT:

After getting some input about secure_path, I checked it:

$ echo $PATH
/home/vyom/.sdkman/candidates/groovy/current/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/lib/jvm/java-17-openjdk-17.0.5.0.8-1.fc37.x86_64/bin:/usr/local/go/bin
$ sudo cat /etc/sudoers | grep "secure_path"
Defaults    secure_path = /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/var/lib/snapd/snap/bin

The secure path contains all */bin folders, but the command starts to work when I use -E env "PATH=$PATH" with sudo.

$ sudo sudo -V | grep "Value to override user's"                                  
Value to override user's $PATH with: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/var/lib/snapd/snap/bin

Relevant content from /etc/sudoers

Defaults   !visiblepw

Defaults always_set_home Defaults match_group_by_gid

Defaults always_query_group_plugin

Defaults env_reset Defaults env_keep = "COLORS DISPLAY HOSTNAME HISTSIZE KDEDIR LS_COLORS" Defaults env_keep += "MAIL QTDIR USERNAME LANG LC_ADDRESS LC_CTYPE" Defaults env_keep += "LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES" Defaults env_keep += "LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE" Defaults env_keep += "LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY"

Defaults secure_path = /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/var/lib/snapd/snap/bin

What is the problem over here?

VIAGC
  • 133
  • 5
  • Adding -E env "PATH=$PATH" flag to sudo makes it work but how is this happening, I am a bit confused. – VIAGC Jan 07 '23 at 19:30
  • 2
    It perhaps indicates that the default sudoers policy is setting the PATH equal to its secure_path, and the latter does not include the location of gzip on your system – steeldriver Jan 07 '23 at 20:10
  • @steeldriver I updated the question to include more information. – VIAGC Jan 08 '23 at 05:45
  • @VyomYdv what is the output of whereis gzip? – Edgar Magallon Jan 08 '23 at 06:00
  • $ whereis gzip gzip: /usr/bin/gzip /usr/share/man/man1/gzip.1.gz /usr/share/info/gzip.info.gz – VIAGC Jan 08 '23 at 06:00
  • It is working now, don't know what the problem is but yesterday, I added export PATH="$PATH:......." to /etc/environment, today I removed those statements and placed them in bashrc and zshrc files, that might be connected to it. – VIAGC Jan 08 '23 at 06:11
  • Yeah, it didn't work that is why I added it to bashrc and zshrc – VIAGC Jan 08 '23 at 13:18
  • Yeah see for example https://unix.stackexchange.com/a/664301/65304 – steeldriver Jan 08 '23 at 13:23

0 Answers0