如何为包括sudo在内的用户启用系统范围的功能? [英] How to enable a system-wide function for users including sudo?

查看:105
本文介绍了如何为包括sudo在内的用户启用系统范围的功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为 killprocessatport 创建一个全局别名,所以我将/etc/bash.bashrc

I want to make a global alias for killprocessatport so I put at the end in /etc/bash.bashrc

fuserfunction() {
    fuser -KILL -k -n tcp $1
}
alias killprocessatport=fuserfunction

然后我在最后输入/etc/profile

源/etc/bash.bashrc

然后我用 bash/etc/profile 加载它,并期望带有参数的别名能够正常工作,但是它却没有:

And then I load it with bash /etc/profileexpecting the alias with parameter to work but it doesn't:

$ killprocessatport 80
killprocessatport: command not found

为什么不呢?

推荐答案

在这种情况下,您不能使用别名函数.在PATH上的位置中创建一个可执行脚本(如果您的/etc/suoders 修改了根的PATH,则由sudo配置).

You can't use an alias or a function in this case. Create an executable script in a location that's on your PATH (as configured by sudo, if your /etc/suoders modifies root's PATH).

#!/bin/sh
exec fuser -KILL -k -n tcp "$@"

保存脚本,然后使用 chmod + x 设置其权限.

Save the script, then set its permissions with chmod +x.

这篇关于如何为包括sudo在内的用户启用系统范围的功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆