我已经在我的机器上安装了postfix,我正在以编程方式(使用python)动态更新virtual_alias(在某些操作上).一旦我更新/ etc/postfix/virtual_alias中的条目,我就运行命令:
sudo /usr/sbin/postmap /etc/postfix/virtual_alias 2>>/work/postfix_valias_errorfileRun Code Online (Sandbox Code Playgroud)但是我收到了错误:sudo: sorry, you must have a tty to run sudoRun Code Online (Sandbox Code Playgroud)
我想以非人类的方式运行提到的sudo命令(意思是,我从python脚本运行这个系统命令.).那么如何以编程方式运行此命令?
使用该os/exec包,我想代表另一个用户在*nix OS上运行外部命令(当然是在具有su权限的另一个用户的root用户下运行进程)
我想避免使用"su"或"bash"命令,并将其与go完全一致.
我使用了一个方法,syscall.Setuid但这会将用户更改为主项目,我只需要将用户更改为外部子进程:
func (self *Command) LoseTo(username string) {
u, err := user.Lookup(username)
if err != nil {
fmt.Printf("%v", err)
}
uid, err := strconv.Atoi(u.Uid)
if err := syscall.Setuid(uid); err != nil {
fmt.Printf("%v", err)
}
}
Run Code Online (Sandbox Code Playgroud) 当我尝试启动postgresql时出现错误:
postgres
Run Code Online (Sandbox Code Playgroud)
postgres不知道在哪里可以找到服务器配置文件.
您必须指定--config-file或-D invocation选项或设置PGDATA环境变量.
那么我尝试设置我的配置文件:
postgres -D /usr/local/var/postgres
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
postgres无法访问服务器配置文件"/usr/local/var/postgres/postgresql.conf":权限被拒绝
嗯好的 接下来,我尝试执行与管理员相同的操作:
sudo postgres -D /usr/local/var/postgres
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
不允许"root"执行PostgreSQL服务器.
必须在非特权用户ID下启动服务器,以防止可能的系统安全性受损.有关如何正确启动服务器的详细信息,请参阅文档.
我搜索了该错误消息,但无法找到解决方案.
任何人都可以对此提供一些见解吗?
试图安装PHP,这需要在其中创建扩展目录/usr/lib/php/extensions.安装返回错误"不允许操作".
我已经发现,sudo无法创建任何目录/usr/.有人经历过这个吗?
在我的应用程序目录中(在Windows上)我运行:
sudo pdfkit --install-wkhtmltopdf
Run Code Online (Sandbox Code Playgroud)
正如这里解释的那样,但我收到了这个错误:
'sudo'不被识别为内部或外部命令,可操作程序或批处理文件.
可能是什么问题呢 ?
我已经设置了一个david具有sudo权限的用户的盒子.我可以进入框中并执行sudo操作apt-get install.当我尝试使用Ansible的"成为特权升级"做同样的事情时,我收到一个permission denied错误.所以一个简单的剧本可能看起来像这样:
simple_playbook.yml:
---
- name: Testing...
hosts: all
become: true
become_user: david
become_method: sudo
tasks:
- name: Just want to install sqlite3 for example...
apt: name=sqlite3 state=present
Run Code Online (Sandbox Code Playgroud)
我使用以下命令运行此playbook:
ansible-playbook -i inventory simple_playbook.yml --ask-become-pass
Run Code Online (Sandbox Code Playgroud)
这给了我一个密码的提示,我给出了,我得到以下错误(缩写):
fatal: [123.45.67.89]: FAILED! => {...
failed: E: Could not open lock file /var/lib/dpkg/lock - open (13:
Permission denied)\nE: Unable to lock the administration directory
(/var/lib/dpkg/), are you root?\n", ...}
Run Code Online (Sandbox Code Playgroud)
为什么我被拒绝了?
附加信息
我正在运行Ansible 2.1.1.0并且我的目标是Ubuntu 16.04.如果我按照Ansible <v1.9 使用remote_user和 …
我是Linux终端的新手,现在我尝试使用sudo,apt-get,whereis等,linux中的命令返回错误bash:sudo:command not found
我的命令
$sudo apt-get install libc6-dev
Run Code Online (Sandbox Code Playgroud)
错误是
bash: sudo: command not found.
Run Code Online (Sandbox Code Playgroud)
请告诉我这里可能出现的问题,提前谢谢
不记得我在哪里读到这个,但无论是在这里的某个地方,还是在我关注的教程的评论中,一个人说:
'永远不要使用sudo pip install; 你可以在不知情的情况下覆盖重要的东西.使用pip install --user代替!'
虽然我看到很多关于sudo pip安装的引用,所以这个人知道他们在谈论什么,我应该避免它,或者......?
我可以使用sudo或su以另一个用户身份执行命令.通过组合exec,我能够用sudo或替换当前进程su,以及运行命令的子进程.但我想用另一个用户运行的命令替换当前进程.我怎么做?
使用sleep inf命令和someguy用户进行测试:
exec su someguy -c 'sleep inf'
Run Code Online (Sandbox Code Playgroud)
这给了我pstree:
bash???su???sleep
Run Code Online (Sandbox Code Playgroud)
和
exec sudo -u someguy sleep inf
Run Code Online (Sandbox Code Playgroud)
给
bash???sudo???sleep
Run Code Online (Sandbox Code Playgroud)
在这两种情况下,我只想要sleep命令,bash作为父命令.
我希望我能有什么的一些序列做到这一点由C setuid()和exec().
我最近将我的系统从 Ubuntu 18.04 更新到 20.04。之后,我尝试使用此处提到的 shell 命令更新我所有的 pip3 包(我将“pip”更改为“pip3”)。
在更新了几个包后,出现了这个提示: KDE Wallet Service
由于我在更新/安装软件包时从未见过它,因此我取消了它,导致立即重新打开相同的提示,并且终端显示以下警告:
WARNING: Keyring is skipped due to an exception: Failed to unlock the keyring!
Run Code Online (Sandbox Code Playgroud)
在它尝试安装的下一个包发生同样的情况后,我按下了 CTRL+C。从那时起,当我尝试安装软件包时,也会发生同样的情况。
例子:
pip3 install numpy
WARNING: Keyring is skipped due to an exception: Failed to unlock the keyring!
WARNING: Keyring is skipped due to an exception: Failed to unlock the keyring!
Collecting numpy
WARNING: Keyring is skipped due to an exception: Failed to unlock the keyring!
Using cached numpy-1.19.2-cp38-cp38-manylinux2010_x86_64.whl (14.5 …Run Code Online (Sandbox Code Playgroud) sudo ×10
exec ×2
linux ×2
pip ×2
privileges ×2
python ×2
ansible ×1
apt-get ×1
bash ×1
go ×1
kde ×1
pdfkit ×1
postgresql ×1
python-3.x ×1
root ×1
shell ×1
sysadmin ×1
ubuntu-12.04 ×1
ubuntu-20.04 ×1
wkhtmltopdf ×1