Emacs is not just a text editor, but a platform to manage your GNU/Linux sever. We are going to show you how to use Emacs daemon to manage your server.
Most regular command line software in GNU/Linux cannot run on background as a daemon. After closing your ssh connection, they will shutdown immediately. In world of GNU Emacs, this situation is not a problem.
First, we recommend you to install the pure command line version of Emacs onto your server. It will save your memory and disk space.
In Debian/Ubuntu/Trisquel, run this command:
sudo apt-get install emacs-nox
In Fedora, run:
sudo dnf install emacs-nox
Second, run the emacs daemon:
emacs --daemon
When you see something like this, the emacs daemon started successfully:
Warning: due to a long standing Gtk+ bug http://bugzilla.gnome.org/show_bug.cgi?id=85715 Emacs might crash when run in daemon mode and the X11 connection is unexpectedly lost. Using an Emacs configured with --with-x-toolkit=lucid does not have this problem. Loading /usr/share/emacs/site-lisp/site-start.d/autoconf-init.el (source)... Loading /usr/share/emacs/site-lisp/site-start.d/autoconf-init.el (source)...done Loading /usr/share/emacs/site-lisp/site-start.d/cmake-init.el (source)... Loading /usr/share/emacs/site-lisp/site-start.d/cmake-init.el (source)...done Loading /usr/share/emacs/site-lisp/site-start.d/desktop-entry-mode-init.el (source)... Loading /usr/share/emacs/site-lisp/site-start.d/desktop-entry-mode-init.el (source)...done Loading /usr/share/emacs/site-lisp/site-start.d/git-init.el (source)... Loading /usr/share/emacs/site-lisp/site-start.d/git-init.el (source)...done Starting Emacs daemon.
Now we run emacsclient to use it:
emacsclient -nw
You will see this screen. Welcome to world of Emacs and free software!
In the following parts, we will show you how to run command line software on the background without keeping ssh connection.
First, we press ALT + x, then, type "term" (without quotation mark), then press Enter two times.
You will see this. Are you familiar with this? Yes, this is bash, the default Unix comand line like what you use everyday.
Second, we run our program. In this example, we run wget to download a large file.
wget https://download.fedoraproject.org/pub/fedora/linux/releases/23/Workstation/x8664/iso/Fedora-Live-Workstation-x8664-23-10.iso
Finally, if you like to close the ssh, all you need to do is to close your terminal emulator, or you can type Ctrl + c, then type 5, then type 0 to close the emacsclient frame. In this process, our downloading will not stop. Then you can close your ssh by typing exit
At the next time you enter your ssh, you DON'T need to run emacs daemon again. You just need to run emacsclient -nw
, then repeat the steps above.
Emacs is an extremely complicated and advanced software, so this is just a very tiny part of it. We may have more articles in the future to show its magic for you.
Have fun, be free.