#+TITLE: Org SSH Export #+DATE: 2020-10-19T21:22:28-04:00 #+DRAFT: true #+DESCRIPTION: #+TAGS[]: emacs org-mode ssh #+KEYWORDS[]: emacs org-mode ssh #+SLUG: #+SUMMARY: I manage a lot of servers. Some are serving static content like this blog, with others running services like [[https://nextcloud.com/][Nextcloud]], [[https://wiki.znc.in/ZNC][ZNC]], [[https://shadowsocks.org/en/index.html][Shadowsocks]], or [[https://www.mumble.info/][Mumble]]. I have one or two game servers to play with my family and friends. These are spread across two providers because for cost and geographic reasons. I also have several machines running in my house, one running FreeNAS with some jails, another running Proxmox with several VMs and containers. I also have a couple smaller single board PCs like Raspberry Pis scattered around. Needless to say, I've got a lot to keep track of. I tried using a couple methods of keeping track of what I had running where, the user names, IP addresses, and links. I also had to worry about making sure my =~/.ssh/config= file was always up to date with VMs and containers I create. I'd already been playing with the idea of using an org-mode file to keep track of servers with VMs and containers, as it seemed like that would fit well with the hierarchical structure of org files. What I came up was a system where each server location/provider gets a heading, with the machines in that location as headings under it. If the machine runs VMs or containers, I just put those as headings under the host machine. #+BEGIN_SRC org ,* Scaleway ,** example.com ,** example.org ,* Vultr ,** lambda.cx ,* Home ,** proxmox ,*** pi-hole ,*** openbsd-1 ,** freenas ,*** web-jail #+END_SRC Each machine gets a billet point list of what's running on it, with the text as a link if they're something I can open in-browser. That would be things like static content and web interfaces. I also write details about services underneath their bullet points if I have more details I want to remember. #+BEGIN_SRC org ,* Vultr ,** example.com - Minecraft =/home/minecraft/survival= Port 4587 - [[https://example.com][nginx]] - [[https://example.com:8080/][znc]] ,** example.org - Shadowsocks - Mumble - [[https://example.net][nginx]] #+END_SRC From there I added either an =IP= or =Hostname= properties to each heading, along with other information about the system like =OS=, =SSH_USER=, etc. This allows me to use org-mode's [[https://orgmode.org/manual/Sparse-Trees.html][sparse trees]] to search for, say, all VMs running OpenBSD. It also allows me to manage servers like anything else in org-mode, adding [[https://orgmode.org/manual/Tags.html][tags]], [[https://orgmode.org/manual/TODO-Items.html#TODO-Items][TODO]] entries, [[https://orgmode.org/manual/Working-with-Source-Code.html#Working-with-Source-Code][code blocks]], [[https://orgmode.org/manual/Hyperlinks.html#Hyperlinks][hyperlinks]], [[https://orgmode.org/manual/Tables.html#Tables][tables]], [[https://orgmode.org/manual/Attachments.html#Attachments][attachments]], putting details in [[https://orgmode.org/manual/Drawers.html#Drawers][drawers]], etc. Finally to keep my SSH config up to date, I wrote [[https://github.com/dantecatalfamo/ox-ssh][ox-ssh]]. A backend for org-mode that lets you export your buffer as an SSH configuration file. It takes all of the properties from the server headings and turns them into entries in a configuration file. It [[https://github.com/dantecatalfamo/ox-ssh#usage][supports]] every client configuration option OpenSSH has, so I can maintain my entire SSH client list from within my org-mode file.