Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the method for pycharm to connect to a remote server through ssh

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

The main content of this article is to explain "what is the method of pycharm connecting to a remote server through ssh". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what is the method of pycharm connecting to a remote server through ssh"?

Because I want to use pycharm to connect to the Windows subsystem Ubuntu for development, I found a lot of tutorials that are not detailed enough, took some time, and finally configured successfully.

Summarize the configuration process of pycharm connecting to Window subsystem as follows, and the process of connecting to other remote servers is the same:

I. Ubuntu configuration

1. Install ssh server first:

> sudo apt-get install openssh-server

2. Modify ssh server configuration:

> sudo vim / etc/ssh/sshd_config

The following items need to be modified:

Port 2222 # defaults to 22, but windows has its own ssh service, which is also port 22 for listening, so you need to change UsePrivilegeSeparation noPasswordAuthentication yesAllowUsers youusername # to the user name you used to log in to WSL.

3. Start ssh server:

Sudo service ssh-full-restart

4. Use xshell to test whether you can connect to the subsystem:

The configuration of xshell login ubuntu on windows is as follows: IP is 127.0.0.1, port number is 2222. Enter the user name and password of the subsystem for authentication information to log in successfully.

Note: it should be noted that the command line window of ubuntu cannot be closed. After it is turned off, the sshd service will be turned off and the connection will be disconnected.

Configure the Pycharm server

1. Determine the IP address of the server (the IP address of the connected subsystem is 127.0.0.1). Make sure that the SSH service is enabled and Python is installed, and the local Project is recommodation_system.

2. Configure the code synchronization of the Pycharm server, open Tools-> Deployment-> Configuration, click + on the left to add a deployment configuration, enter the configuration name Name,Type, select SFTP, and then confirm

3. Configure the IP, port, user name and password of the remote server. Root Path is the root directory of the project files in the remote server. Configure according to the requirements, such as / home/rs, this directory requires the creation permission of the login user (after configuring the server parameters, clicking Autodetect on the right will automatically generate Root Path)

4. Click Mappings, and set Local Path to the project directory under Windows, such as D:\ GitHub\ recommodation_system, and set it as appropriate. Set Deployment path on server to the project directory in the remote server, such as / ML. Add / before the directory, otherwise the files will not be found by running the program later, and Web path on server will not be set up for the time being. It seems that Web-related programs will be used. If you need to use it, please Google yourself.

5. Click Excluded Paths to set some directories that you do not want to synchronize, such as the configuration file directory of the software.

6. Open Tools-> Deployment-> Options and tick Create Empty directories. If the specified folder does not exist, it will be created automatically.

Third, Pycharm remote connection to the remote server

1. Select File-> Settings, select Project-> Project Interpreter, and then on the right, click the pinion to set it.

2. Click Add Remote, select SSH Credentials, fill in the SSH configuration information of the host, and Python interpreter path select the interpreter of the remote server (select the required python version), as follows

3. Select the configured remote server, and Path mappings corresponds to the path mapping relationship in step 4 in part 2 (because the file was not properly configured at the beginning, the runtime cannot find the file. In fact, you need to Upload the local file to the corresponding address of the server to run on the server). You can see the Package that has been read to the remote server, as shown below:

4. Before running the program, go to Tools-> Deployment, and select Automatic Upload (always). In this way, the local editing program will be automatically uploaded to the server to avoid running errors due to the inconsistency between the local file and the server file.

5, when running the program, that is, when you click Run, you can debug remotely by selecting the newly configured interpreter, which is basically no different from using a local interpreter.

At this point, I believe you have a deeper understanding of "what is the method of pycharm connecting to a remote server through ssh". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report