How to SSH into cPanel within VS Code for Mac

It’s great to have the entire cPanel from within your VS Code. Think of all the files and folders that you can search, and easily update as if it were your own local environment. It’s already quite instant to make the changes too, and doesn’t involve dragging files and folders into FileZilla for that matter!

pbcopy < ~/.ssh/id_rsa.pub
This will save your SSH public key into your clipboard.If you do not have an SSH key yet, here is a good guide from Atlassian on how to do so.Next, we will have to add this SSH public key into cPanel, so that we can log into the server without needing a password. Therefore, treat your SSH public key the same security as your password:
  • Open cPanel and search for SSH.
  • Click the cPanel SSH module, and click import a new key.
  • And paste your machine’s recently copied SSH public key.
  • No need for password or private key. Save Changes.
  • Re-visit your newly imported SSH key within cPanel, and click Manage Authorization, then click Authorize.
And now that you have the SSH public key added to cPanel and is also authorised, let’s move into VS Code.

Remote SSH

Now we can head over to VS Code, open the app, press Cmd+Shift+P and type Add new SSH Host. Press Enter key, and type the following command, where username is your cPanel username, and serveripaddress is your cPanel server IP Address:
ssh username@serveripaddress.com

If you get an RSA Fingerprint prompt, press Enter.

You should now be connecting to SSH whilst VS Code is installing itself on the server.

Please note that depending on the server environment it might not allow you to continue because it wouldn’t allow VS Code to be installed. You will have to use a non-SSH method to access files and folders instead, which is unfortunate but happens.

If successfully connected, open the Explorer Cmd+Shift+E and click Open Folder, you can then select the directory you want VS Code to load so that you can search around from, usually you can just press Enter.

Now what is happening is that VS Code is loading up the files and folders so that you can have an intuitive experience with searching for files and folders, and searching within the files as well. You can simply save your file, and it will be updated almost instantly onto the server.

Happy remote SSH coding!

...
WP Feedback

Dive straight into the feedback!
Login below and you can start commenting using your own user instantly