从启动器以根用户身份运行Pycharm [英] Running Pycharm as root from launcher

查看:182
本文介绍了从启动器以根用户身份运行Pycharm的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以root用户权限从启动器运行Pycharm?

How is it possible to run Pycharm from the launcher with root privileges?

我可以使用sudo ./pycharm.sh在终端窗口中执行此操作,但我想直接在启动器中执行相同的操作.

I can do that from the terminal window, with sudo ./pycharm.sh, but I'd like to do the same directly from the launcher.

推荐答案

我遇到了另一种解决此问题的方法,因此我想与他人分享(此答案更像是其他答案的替代方法).

I have encounter another way to solve this issue so I thought to share it (this answer is more like an alternative for the other answers).

这里值得一提的是,该解决方案通过仅以root模式运行某个Python脚本(在pycham IDE中)而不是整个pycharm应用程序来攻击"该问题.

It is worth to mention here that this solution "attacks" the problem by running only a certain Python script (within the pycham IDE) in root mode , and not the entire pycharm application.

1)禁用,需要密码才能运行Python:

1) Disable requiring password for running Python:

这将通过编辑/etc/sudoers.d/python文件来实现.我们需要做的是在该文件中添加一个条目,如下所示:

This will be achieved by editing the /etc/sudoers.d/python file. What we need to do is add an entry in that file as follows:

user host = (root) NOPASSWD: full_path_to_python,例如:

guya ubuntu = (root) NOPASSWD /usr/bin/python

注意:

user可以通过以下命令检测:whoami

user can be detected by the command: whoami

host可以通过以下命令检测:hostname

host can be detected by the command: hostname

2)创建"sudo脚本":该脚本的目的是赋予python特权以root用户身份运行.

2) Create a "sudo script": The purpose of this script is to give python privilege to run as root user.

创建一个名为python-sudo.sh的脚本,并将以下内容添加到其中:

Create a script called python-sudo.sh , and add the following into it:

!#/bin/bash

sudo /usr/bin/python "$@"

再次注意,该路径是上一个阶段的Python路径.

Note, again, that the path is the path to your Python as the previous phase.

不要忘记使用以下命令为该脚本赋予执行权限:chmod,即-

Don't forget to give execution permissions to this script using the command: chmod, i.e.-

chmod +x python-sudo.sh

3)使用 python-sudo.sh脚本作为您的pycharm解释器:

3) Use the python-sudo.sh script as your pycharm interpreter:

在pycharm中转到:File --> Settings --> Project interpreter

Within pycharm go to: File --> Settings --> Project interpreter

在右上角单击设置"图标,然后单击添加本地".

At the right top hand side click the "setting" icon, and click "Add local".

在浏览器选项中,选择我们先前创建的python-sudo.sh脚本. pycharm将具有以root身份运行python脚本的特权.

In the browser option choose the python-sudo.sh script we have created previously. This will give pycharm the privilege to run a python script as root.

4)调试:仅在pycharm IDE中调试特定的Python脚本.可以通过右键单击脚本进行调试->点击"Debug sample_script_to_debug.py"

4) Debug the test: All there is left to do is actually debug the specific Python script in the pycharm IDE. This can be done easily via Right-click on the script to debug --> hit "Debug sample_script_to_debug.py"

希望这很有帮助,如果这种方法有任何错误,请告诉我.

Hope it was helpful and let me know if there are any mistakes in this approach.

干杯

人.

这篇关于从启动器以根用户身份运行Pycharm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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