简体   繁体   中英

How to run a python script on a remote ec2 instance using sudo from pycharm

I am running pycharm 2017.2.3. I want to run my python script on a remote ec2 instance using sudo user through pycharm. How do I acieve this?

Follow the steps below:

  1. Go to File -> Settings -> Project Interpreter and add a new interpreter

  2. Click on + to add a new python interpreter and then click on SSH interpreter

  3. Provide your EC2 Public DNS in HOST and ubuntu as username

  4. Click Next and add the private_key.pem file.

See this article for more details: PyCharm setup for AWS automatic deployment

It looks like you can configure your python interpreter over SSH with the professional version of PyCharm.

Configuring Remote Interpreter + PyCharm

Finally found an answer after a researching through the internet. We can have a script on remote machine as a pycharm interpreter. Create a following script on a remote machine and make sure the script is executable.

#!/bin/bash
sudo /usr/bin/python "$@"

Now change the project interpreter to point to the above script on remote machine in pycharm. Now every script you run on local machine gets executed on remote as a sudo user.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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