tar 不能与 sudo 一起使用

tar 不能与 sudo 一起使用

我正在尝试提取文件以/usr/local/使用

$ 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

但是当我更改我有权访问的目录(例如 - /home/vyom/abc)时,它工作得很好

$ 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也不缺

$ 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.

编辑:

在获得有关 的一些输入后secure_path,我检查了它:

$ 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

安全路径包含所有*/bin文件夹,但当我-E env "PATH=$PATH"使用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

相关内容来自/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

这里有什么问题吗?

相关内容