This guide will show you how to use Sublime Text editor locally to edit code files on a remote server via SSH.
This guide assumes oy already have a working SSH connection between your Mac and your remote server (with no firewall issues) and have configured SSH keys via modifying to authorized_keys file to enable SSH access.
Need a server?
UpCloud is way faster than Vulr.
Setting up slower region specific servers can be found here. Set up a Server on Vultr here for as low as $2.5 a month or set up a Server on Digital Ocean (and get the first 2 months free ($5/m server)). I have a guide on setting up a Vultr server here or Digital Ocean server here. Don’t forget to add a free LetsEncrypt SSL Certificate and secure the server (read more here and here).
Buy a domain name from Namecheap here.
Setting up your local machine
Open Sublime Text 3 and press COMMAND+SHIFT+P to bring up the command bar and type Install and click Package Control: Install Package and click it.
Wait a few seconds for the packages list to show and type “rsub”
Ok let’s make an SSH alias to your server on your Mac by typing “sudo nano ~/.ssh/config”
Make these changes
RemoteForward 52698 localhost:52698
Now we can connect to the server via SSH by typing “ssh mysrv”
After typing the server’s password you will be connected to the ssh server
Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.4.0-87-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
0 packages can be updated.
0 updates are security updates.
You have new mail.
Last login: Sat Sep 16 12:51:35 2017 from xx.xx.xx.xx
Now on your local Mac load the following page in a web browser (and review the code): https://raw.github.com/aurora/rmate/master/rmate and copy the contents to the clipboard.
On the remote server (the SSH one) type:
sudo nano /usr/local/bin/rmate
Now paste the contents or this page into nano editor and save it and exit nano.
Now run this chmod command to make the rmate file executable.
sudo chmod a+x /usr/local/bin/rmate
Now on the server, we can open any text file with rmate and have it open locally in Sublime via SSH. Yes, Open a file on a server and have it automatically open in locally 🙂
If you have many files to open then create a bash file to open files with rmate
sudo nano openfilesonmac.sh
chmod +x openfilesonmac.sh
Now we can open may remote files locally by running the bash script.
All saves in Sublime locally are sent to the server 🙂
Still here, read more articles here or use the form below to ask a question or recommend an article.
Port Forwarding with vSSH on OSX
If you use a third party ssh program like vSSH you will also need to setup port forwarding to avoid this error
/usr/local/bin/rmate: connect: Connection refused
/usr/local/bin/rmate: line 384: /dev/tcp/localhost/52698: Connection refused
Unable to connect to TextMate on localhost:52698
Now you can open remote files locally with SSH or vSSH too.
Donate and make this blog better
Ask a question or recommend an article
v1.4 Added UpCloud Info.
v1.3 vSSH Port forwarding.