yae*_*ael 4 linux users sudo group
我将此行添加到visudo,以便向 yael 用户授予完全权限:
yael ALL=(ALL) NOPASSWD: ALL
Run Code Online (Sandbox Code Playgroud)
但是当我想更新/etc/hosts文件时,我的权限被拒绝:
su – yael
echo "10.10.10.10 yael_host">>/etc/hosts
-bash: /etc/hosts: Permission denied
sudo echo "10.10.10.10 yael_host">>/etc/hosts
-bash: /etc/hosts: Permission denied
ls -ltr /etc/hosts
-rw-r--r--. 1 root root 185 Aug 7 09:29 /etc/hosts
Run Code Online (Sandbox Code Playgroud)
我怎样才能像 root 一样给予用户 yael 能力?
Yar*_*ron 21
问题的根源在于输出重定向是由 shell(用户 yael)完成的,而不是由sudo echo.
为了强制写入/etc/hosts将由用户root而不是用户完成yael- 您可以使用以下格式:
echo "10.10.10.10 yael_host" | sudo tee --append /etc/hosts
Run Code Online (Sandbox Code Playgroud)
或者
sudo sh -c "echo '10.10.10.10 yael_host'>>/etc/hosts"
Run Code Online (Sandbox Code Playgroud)