Emacs Tramp brings the power of SSH into your text editor. You no longer need to open a separate terminal window in order to run scripts, edit files, or perform other server maintenance. Tramp lets you do it all right inside of an Emacs buffer.
There are only two things you would ever need to do in your server:
- Edit files
- Run scripts
These tasks can be easily accomplished with a basic terminal emulator and SSH. You can log into your server, run scripts, edit files, and do all the work you need to do. But with Emacs, you don’t need a terminal emulator to do these things.
When you are prompted to open a file or directory in Emacs, you can instead add an access method to the directory path. In this article, I will use SSH, but there are others.
Behind the scenes, invisible to the user, Emacs establishes a connection with your server and allows you access files as though they were located on your local computer.
This means you can bring all of your Emacs configurations and expressions with you during your server login session. You can also seemlessly switch back and forth between local and remote buffers; as you probably know, copying and pasting text to and from text-based terminals can be an annoying chore.
Tramp works alongside dired to give you the same functionality remotely as you enjoy locally. All you need to do is construct the directory path differently. But basically you are using the
find-file function (or,
C-x C-f) as normal.
In order to open a Tramp buffer just type
C-x C-f and append the “ssh:” method to a directory path:
Of course, replace “example.com” with your domain name. If you wait a moment for the connection to be established, you will be prompted to unlock your SSH key, and asked if you would like to save your autentication information. Then you will be brought into a dired window displaying the files and directories in your server’s home folder for the
Your Tramp session inherits whatever privileges belong to the user you logged in as. If you log in as the
root user, you have complete access to your server.
Otherwise, you would need to pass sudo privileges into your session:
Even simpler, if your user does not require superuser in order to complete its desired operations then you don’t need to pass
sudo into your access method.
Check out other Emacs resources: