'VS Code, how to run Python on a remote server as a different user?
An issue happens on the server but not in IDE, so we want to use Visual Studio Code to SSH to the server and run the Python program for debugging.
We usually login to the server with the personal username issued by corporate IT. However, when calling sudo systemctl start xxx.service, it starts running as a different user, and we don't know its password. The content of the service file is attached below.
We could use sudo to set the password of the app user and then connect VSCode with the credential. But, it's not elegant.
So, we wonder if there is a way to connect VSCode following the same path of regular operation: login through SSH with the personal username, then become the designated app user and start running the Python program.
Sample of file xxx.service:
[Unit]
Description=gunicorn daemon
After=network.target
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=appuser
Group=webapp
WorkingDirectory=/data/webapp/APPLICATION
ExecStart=/data/webapp/APPLICATION/run/gunicorn_start
[Install]
WantedBy=multi-user.target
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
