Connect Visual Studio Code to cPanel via SSH

Connect Visual Studio Code to cPanel via SSH

Connecting Visual Studio Code to your cPanel hosting service is a simple task using the Remote - SSH plugin.

If you haven't installed this plugin in VS Code yet, go to the Extensions icon on the left sidebar (or press Ctrl + Shift + X) and search for "Remote - SSH". Once installed, you can continue with this guide.

Create a connection key from Windows

Open the terminal on your computer (CMD) and type the following command:

ssh-keygen



  1. You will be asked for a key name. You can assign any name you prefer.
  2. Next, you will need to enter a password (passphrase) twice. We recommend leaving it empty and pressing Enter twice.
  3. Navigate to the directory C:\Users\YOUR_USER\.ssh where you will find two generated files: your public key (.pub) and your private key.
  4. Open both files with any text editor and copy their contents. You will need them in the next step.

Import key in cPanel

  1. Log in to cPanel and look for the SSH Access option.
  2. Click on Manage SSH Keys and then on the Import Key button.


  1. Assign the same name you used when generating the key in CMD.
  2. Paste the contents of the private key and public key in the corresponding fields.
  3. In the Public Keys section, click Manage and then the Authorize button.

Your key is ready to use.

Generate key in cPanel (alternative method)

If you prefer to generate the key directly from cPanel instead of importing it:
  1. Log in to cPanel and type "SSH" in the search bar. Click on Manage SSH Keys.


  1. Click on + Generate a new key and fill in the form: assign a name to your key, set a password, and click Generate Key.


  1. Click Manage to authorize the key and then select Authorize.



  1. Click View/Download and download the private key using the Download button.



  1. Save the file in a permanent folder on your computer. You will need this path to configure VS Code.

Connect Visual Studio Code on Windows

  1. Open VS Code and press F1.
  2. Select Remote-SSH: Open SSH Configuration File.
  3. Add the following configuration:
Host yourdomain.com
  HostName yourdomain.com
  User your_cpanel_user
  IdentityFile C:\Users\YOUR_USER\.ssh\key_name

Replace the values in the block above with your actual domain, cPanel username, and path to your private key.
  1. Press F1 again and select Remote-SSH: Connect to Host. Choose the host you just configured.
  2. Once connected, click on Explorer (Ctrl + Shift + E), select Open Folder, and choose public_html.

Done! You are now connected to your server from Visual Studio Code.

Connect Visual Studio Code on Mac

  1. Right-click on the downloaded key file, hold the Option key, and select "Copy as Pathname".
  2. Open the Terminal and adjust the file permissions:
chmod 0700 /full/path/to/your/key

  1. Open VS Code and click the remote connection icon in the bottom-left corner (it looks like ><).


  1. Select "Connect to Host" and then "Configure SSH Hosts...". Choose the file /Users/YOUR_USER/.ssh/config.


  1. Add the following configuration and save the changes:
Host MySite
  HostName yourdomain.com
  User your_cpanel_user
  IdentityFile "/full/path/to/your/key"



  1. Repeat step 3, select "Connect to Host..." and choose the host you just created. You will be asked for the password you set when creating the key in cPanel.



Wait for the connection to be established and you're all set! You can now work on your server directly from VS Code.
    • Related Articles

    • How to Block IP Addresses in cPanel to Protect Your Website

      Not all traffic reaching your website is legitimate. Malicious bots, unauthorized access attempts, and brute force attacks are common threats that can compromise the security and performance of your server. Blocking unwanted IP addresses is one of ...
    • How to Fix cPanel "Loading Your Email Accounts" Slow Issue

      Is your cPanel stuck "loading" forever when searching for email accounts? Do you see the "Loading your email accounts..." message for several seconds or even minutes? You are not alone! We have discovered the solution to this problem that affects ...
    • How to Create Full and Partial Backups in cPanel

      Having up-to-date backups of your information is invaluable for the continuity of any project or business. At Webzi, we maintain a robust and well-defined backup policy. As part of our service and at no additional cost, we perform automatic backups ...
    • How to Set Up a Remote MySQL Connection in cPanel

      With the growing need to access databases remotely to manage applications and websites, setting up a remote MySQL connection has become an essential skill for developers and system administrators. This tutorial will guide you step by step through the ...
    • PHP Versions and Extensions in cPanel

      At Webzi, we provide the most popular PHP versions and allow users to select the extensions needed for their development. Below we explain how to do it: Log in to the cPanel control panel using your administrator credentials. Inside cPanel, look for ...