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?

8
  • Adding -E env "PATH=$PATH" flag to sudo makes it work but how is this happening, I am a bit confused.
    – VIAGC
    Jan 7, 2023 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 Jan 7, 2023 at 20:10
  • @steeldriver I updated the question to include more information.
    – VIAGC
    Jan 8, 2023 at 5:45
  • @VyomYdv what is the output of whereis gzip? Jan 8, 2023 at 6:00
  • $ whereis gzip gzip: /usr/bin/gzip /usr/share/man/man1/gzip.1.gz /usr/share/info/gzip.info.gz
    – VIAGC
    Jan 8, 2023 at 6:00

0

You must log in to answer this question.

Browse other questions tagged .