简体   繁体   English

如何在Linux中将命令列入黑名单?

[英]How do I blacklist a command in Linux?

I would like to blacklist a command in Linux or add it to sudo to avoid typing it by accident. 我想将Linux中的命令列入黑名单或将其添加到sudo中,以免意外输入。

I was trying to fix my RVM and for some reason typed: 我试图修复我的RVM并由于某种原因输入了:

rvm reset

And lost all my gemsets. 失去了我所有的宝石。

I would like to change this behavior to sudo rvm reset and perhaps add a comment that says what this command will do. 我想将此行为更改为sudo rvm reset ,也许sudo rvm reset添加一条注释,说明该命令将执行的操作。

I would wrap a shell function around rvm: 我将在rvm周围包装一个shell函数:

rvm () {
    case $1 in
        reset)
            echo "danger Will Robinson" >&2
            echo "run 'command rvm reset' if you really want it" >&2
            ;;
        *) command rvm "$@" ;;
    esac
}
chown root `which rvm` 
chmod 0700 `which rvm`

to restrict gemset delete command use something like this: 要限制gemset delete命令,请使用以下命令:

chown -R root `rvm gemdir`
sudo chmod -R 0755 `rvm gemdir`

even chmod maybe unnecessary. 甚至chmod也许都是不必要的。 But you'll need sudo for new gemset installations. 但是对于新的gemset安装,您将需要sudo。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM