小编XPD*_*DIN的帖子

在 /etc/sudoers 中为某些特定命令添加 NOPASSWD

在没有密码的情况下使用超出的密码是否有任何风险?

这是一台家用电脑,没有其他用户使用它,我只使用安装 Ubuntu 时默认创建的单个用户。

我想根本不必为这些命令写 sudo 密码:

echo 100 > /sys/class/backlight/intel_backlight/brightness

ethtool -s eth0 autoneg off speed 100 duplex full

dhclient eth0

apt-get update && upgrade && dist-upgrade -y

apt-get autoremove && remove && clean && autoclean -y
Run Code Online (Sandbox Code Playgroud)

谢谢你。

回答: 看来这些步骤解决了这个案例:

sudo su
Run Code Online (Sandbox Code Playgroud)

在其中创建/usr/local/bin/scriptname并写入超出的行:

#!/bin/bash

command in here without sudo

# the end of the script's name
Run Code Online (Sandbox Code Playgroud)

_

Create /etc/sudoers.d/scriptname and write the following lines in it:

User_Alias scriptname=username
Cmnd_Alias scriptabreviaton=/home/globalisation/r
scriptname ALL=NOPASSWD: scriptabreviaton
Run Code Online (Sandbox Code Playgroud)

/etc/sudoers接下来的两行末尾添加:

username …
Run Code Online (Sandbox Code Playgroud)

ubuntu sudo

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

sudo ×1

ubuntu ×1