Connect to Server via SSH through Visual Studio Code
-
I am able to connect to my server via the terminal successfully, but not through Visual Studio Code when using the “Remote – SSH” extension.
I have conducted extensive research on the matter and have tried the following without results:
- Delete .vscode-server from root
- Change all permissions with chmod -R 777 ( I know this is not smart but wanted to test if this would resolve issues).
- Ensure the config file is properly setup.
Below I’ve pasted a few interesting lines from the log.
[22:56:04.377] Terminal shell path: C:WindowsSystem32cmd.exe [22:56:08….]: running > Script executing under …> Found existing installation at /home/…/.vscode-server… > Starting VS Code CLI… > Removing old logfile at /home/..> Spawned remote CLI: 31 > Waiting for server log… [22:56:08.064] Got some output, clearing connection timeout [22:56:08.111] > Waiting for server log… > sh: 413: kill: No such processExec server process not found > [2025-02-27 21:56:10] error error listening on port: Operation not permitted (os error 1)
It seems that I’m able to establish a connection but that it disconnected by the server.
Based on what I’ve read on the internet, it should be possible to connect to my server via SSH on vsc. I’m interested in this because I want to split my functions.php into separate files and want to use vsc as the editor for this.
-
Hello! Anyone can contribute to this conversation, but please do keep in mind that my scope is extremely limited on this issue.
I believe that the key to this problem lies in this error message that you shared:
[2025-02-27 21:56:10] error error listening on port: Operation not permitted (os error 1)I can’t tell you exactly what it was, but some operation that Visual Studio Code is trying to perform is not permitted by our server. I’d probably suggest reaching out to them or asking in their forums if there’s anything they can draw from this, since it’s possible that you could stop VSCode from attempting the prohibited operation.
I hope that helps somewhat!
-
The error message you’re encountering,
error listening on port: Operation not permitted (os error 1), suggests that the Visual Studio Code (VS Code) Remote-SSH extension is facing issues establishing a connection. Here are some steps to troubleshoot and resolve this problem:- Enable TCP Forwarding on the Remote Server:
- Modify SSH Configuration:
- Access the SSH configuration file on your remote server:
sudo nano /etc/ssh/sshd_config - Locate the line containing
AllowTcpForwardingand set it toyes:AllowTcpForwarding yes - If the line is absent, add it to the file.
- Access the SSH configuration file on your remote server:
- Restart SSH Service:
- After saving the changes, restart the SSH service to apply them:
sudo systemctl restart ssh
- After saving the changes, restart the SSH service to apply them:
- This configuration allows SSH to forward ports, which is essential for the VS Code Remote-SSH extension to function correctly.
- Modify SSH Configuration:
- Remove Existing VS Code Server Files:
- Corrupted or outdated server files on the remote machine can cause connection issues.
- Delete the
.vscode-serverDirectory:- On the remote server, execute:
rm -rf ~/.vscode-server - This command removes the existing VS Code server files, prompting a fresh installation upon the next connection attempt.
- On the remote server, execute:
- Verify SSH Port Configuration:
- Ensure that the SSH service on the remote server is listening on the correct port (default is 22).
- Check SSH Configuration:
- In the
/etc/ssh/sshd_configfile, verify thePortdirective:Port 22 - If a different port is specified, ensure that your SSH client and VS Code are configured to use that port.
- In the
- Update VS Code SSH Configuration:
- In your local machine’s SSH configuration file (usually
~/.ssh/config), specify the correct port:Host your_remote_host
HostName your.remote.host
User your_usernamePort 22 - Replace
your_remote_host,your.remote.host,your_username, and22with your remote host’s alias, hostname, username, and the correct SSH port, respectively.
- In your local machine’s SSH configuration file (usually
- Check for Conflicting Processes:
- The error may indicate that another process is using the required port or that the VS Code server process didn’t start correctly.
- Identify Conflicting Processes:
- On the remote server, list processes using network ports:
sudo lsof -i -P -n | grep LISTEN - Look for any processes that might be using the port required by VS Code and terminate them if necessary.
- On the remote server, list processes using network ports:
- Kill VS Code Server Processes:
- Terminate any existing VS Code server processes to allow a clean start:
pkill -f vscode-server - Alternatively, from VS Code on your local machine, press
Ctrl + Shift + Pto open the command palette, then execute:Remote-SSH: Kill VS Code Server on Host... - Select the appropriate host to terminate the server processes.
- Terminate any existing VS Code server processes to allow a clean start:
After performing these steps, attempt to reconnect to the remote server using the VS Code Remote-SSH extension. If issues persist, consider updating both VS Code and the Remote-SSH extension to their latest versions, as updates often include fixes for known issues.
For more detailed information and community discussions on this topic, you can refer to the following resources:
[redacted by staff]
- Enable TCP Forwarding on the Remote Server:
-
Having done some further investigation into this it seems that VSCode’s Remote SSH extension initially connects correctly via port 22. This is an open port on WordPress.com. Once it has a connection it then copies what is required and tries to connect over a port that is not open in the firewall, possibly port 5000.
As per our support documentation at https://wordpress.com/support/firewall-rules/, there are limited ports that are open. If a third-party system tries to connect over a port that is not open then the connection will be rejected.
If VSCode is able to use an SFTP connection instead then you might be able to achieve what you are trying that way as this would use the open port 22 at all times.
-
@hideandgeek404 @honhonjaccuse @maxxpainkiller
Thank you everyone for trying to help. Unfortunately, the issue is still unresolved, the suggestions of Max didn’t do the trick…
@hideandgeek404 What I don’t seem to understand is that I’m not the first one trying to connect to wordpress.com via SSH on vsc, so it would be weird if others wouldn’t have run into this same issue. Having said that, everything in the log does point to that direction, everything’s smooth sailing until “Starting VS Code CLI…”, so perhaps it is trying to open it somewhere where it is not allowed. Do you have any idea how I could check this?
Perhaps I can open another thread for this, but what do you development setup/workflow do you suggest as an alternative?
My idea had been to connect to my child theme on vsc to make the relevant edits (create new files, functions, etc.) I
-
Perhaps I can open another thread for this, but what do you development setup/workflow do you suggest as an alternative?
My idea had been to connect to my child theme on vsc to make the relevant edits (create new files, functions, etc.)
It sounds like the Remote – SSH extension may be trying to do some things in ways that are not permitted on WordPress.com. I did some testing on my end using the extension and had trouble connecting not only to a WordPress.com site but also to a local Raspberry Pi, while both of these work fine through a terminal or connection via an SFTP program. So it seems that the extension expects a very specific configuration on the server itself. We would suggest contacting the developer of the extension or looking at using an alternative extension. Since Visual Studio Code and its extensions are third-party, we are limited in the support we can provide.
As far as other development options, there are several options you can consider including using the WordPress.com Studio app (which would allow you direct access to a local copy of the files). You can also use the GitHub deployment features included with WordPress.com Business plan (or higher). You might also look for something that can upload files over SFTP such as FileZilla (or another program) or simply run commands from your terminal. Which one you choose will depend on what your needs are or preferences are. Here are some links to these options:
- The topic ‘Connect to Server via SSH through Visual Studio Code’ is closed to new replies.