Getting started
Two words are used throughout. A pass is one read of a server. When a pass finds that something changed, Lemano records a new numbered generation. An object is one thing a pass reads: a file, a package, a service, a user.
Install
Install a release with the script, which puts lemano and
lemano-ansible in ~/.local/bin after checking the archive’s SHA-256:
curl -fsSL https://lemano.dev/install.sh | shThe install page has the packages, the
container image, go install, a build from source, and how to verify a
download.
If ssh already reaches the server
If ssh web-01 works from your machine and the account it logs in with
may run sudo without a password, a target file can name that alias:
# targets/web-01.yaml
apiVersion: lemano.dev/v1alpha1
kind: Target
metadata:
name: web-01
spec:
connector:
type: ssh
host: web-01
user: you # leave out if your ssh config sets User for web-01Lemano takes the host name, port, keys and jump hosts from your ssh
config (see Using your SSH config); its own
default user is lemano, so name your account when your config does not.
Then go on with Describe the server and read it
below, with this file in place of the one there.
A dedicated account
For a server you keep under Lemano, give it an account of its own that
may run one command and nothing else. Lemano logs in with an SSH key and runs its scripts as root through
sudo. On each server, create a login for it, give it your key and allow
that one command. First make a key on your machine (a key with a
passphrase works only through an SSH agent; see
storing passwords and keys):
ssh-keygen -t ed25519 -N '' -f keys/web-01Then, on the server, as root:
useradd --create-home --shell /bin/sh lemano
install -d -m 0700 -o lemano -g lemano /home/lemano/.ssh
echo 'ssh-ed25519 AAAA... lemano@workstation' > /home/lemano/.ssh/authorized_keys # the line of keys/web-01.pub
chown lemano:lemano /home/lemano/.ssh/authorized_keys
chmod 0600 /home/lemano/.ssh/authorized_keys
echo 'lemano ALL=(root) NOPASSWD: /bin/sh -s' > /etc/sudoers.d/lemano
visudo -cf /etc/sudoers.d/lemanoThe sudoers line lets the account run sh -s, which reads a script from
standard input, and nothing else; the security model
explains why, and what to do if sudo asks for a password. If you would
rather not give the account sudo at all, set privilege: user in the
target file below: Lemano then reads what an ordinary account can read,
and lists what only root can read as skipped.
Describe the server and read it
Describe a server in a target file. The credential names a private key
file, relative to the target file’s folder (here keys/web-01 beside the
targets folder); it is never copied into the store:
# targets/web-01.yaml
apiVersion: lemano.dev/v1alpha1
kind: Target
metadata:
name: web-01
labels:
env: prod
spec:
connector:
type: ssh
host: 192.0.2.10
user: lemano
credential: file:../keys/web-01Create the store and its key, then run a first discovery. The first connection pins the server’s host key; after that, a changed key is always refused.
$ lemano init
Created the store at /home/you/.local/share/lemano/lemano.db
Created the key file at /home/you/.config/lemano/key (mode 0600)
The store is unrecoverable without this key. Back up the key file now,
and keep the copy apart from the store and its backups: a printed copy works,
as the key is one line of text with a checksum.
$ lemano discover -f targets --accept-new-host-key
TARGET RESULT GENERATION PRIVILEGE NOTE
web-01 changed 0 root first discovery; pinned SHA256:Ax4w84I5lO17nCN4oIWc/AlyfILs0uECccTPrbBxq1YSee what changed
Later passes write a new generation only when something changed. Here the server’s host name was changed between two passes:
$ lemano discover -f targets
TARGET RESULT GENERATION PRIVILEGE NOTE
web-01 unchanged - root -
$ lemano discover -f targets
TARGET RESULT GENERATION PRIVILEGE NOTE
web-01 changed 1 root changed: hostname; objects: 0 added, 0 removed, 1 changed
$ lemano diff web-01 0 1
web-01: generation 0 -> 1
Facts:
~ hostname: "web-01" -> "web-01-old"
Objects:
~ Sysctl/kernel.hostname
~ status.live: "web-01" -> "web-01-old"
$ lemano verify web-01
web-01: the chain verifies: 2 generation(s), 1582 object(s), 149 blob(s); no errors were foundlemano history web-01 --passes lists every generation and every pass,
with the periods when the server was not seen; reading the
history shows its output, and
how to list the objects of a generation. Lemano has no daemon: a pass runs
only when you, a timer or Ansible start it, so
schedule lemano discover with a
systemd timer or cron.
The daily loop: the timer runs a pass every hour, then lemano summary,
which says in one line what changed since yesterday and, below it, which
servers need you and the command to act on each: who changed what,
grouped (“12 packages upgraded by apt (unattended-upgrade)”), servers not
read, open conditions. Keep it in a file for a dashboard, in Prometheus
form for node_exporter, or in a shell’s login file: see
seeing what changed every day.
Contents and secrets
A field that can hold a secret, such as a cron command or sshd’s
ForceCommand, shows in a diff as (sensitive value), never with its value
or its keyed hash.
When the content of a file changed, the diff shows the lines that changed, read from the encrypted copies the store keeps and decrypted in memory for the command:
$ lemano diff web-01 1 2
~ File//etc/hosts
~ content changed
--- /etc/hosts (generation 1)
+++ /etc/hosts (generation 2)
@@ -1,3 +1,3 @@
127.0.0.1 localhost
-::1 localhost
+::1 localhost ip6-localhost
10.0.0.5 db
~ File//etc/app/secret.conf
~ content changed (not shown: the file may hold secrets, it is not world-readable)Content is shown only for a text file that every user can read, in both
generations, that the target’s contentExcludePaths do not name, and that
is not a file of sealed text such as a crontab, a sudoers file or sshd’s
configuration, and that does not look like it holds secrets (a .env
file, a private key, an assigned password or token).
--show-secrets also shows the files that only some users can read, the
files of sealed text and the files that look like they hold secrets;
--no-content shows none. -o json and -o yaml carry the same content
diffs, under the same rules.
Compare with a baseline
To compare a server with a state you have checked, accept a generation as its baseline. Every object is then in sync, changed, added or missing against it:
$ lemano baseline web-01 0
Baseline of web-01: generation 0 (accepted now by you)
Against it, generation 1 has 1580 in sync, 1 changed, 0 added, 0 missing; see: lemano diff web-01 --baselinelemano diff web-01 --baseline lists the objects that are not in sync,
with their changed fields. To accept only some of them, name them:
lemano baseline web-01 --only /etc/hosts, or take all but a few with
--skip.
Put a file back
To put files back, revert to a generation. Lemano takes the server’s lock, reads it again, shows what the revert changes and asks before it writes:
$ lemano revert web-01 --to 1 /etc/hosts
web-01: revert to generation 1 (live state read just now, generation 2)
Files:
~ /etc/hosts
~ content changes
--- /etc/hosts (live)
+++ /etc/hosts (generation 1)
@@ -1,3 +1,3 @@
127.0.0.1 localhost
-::1 localhost ip6-localhost
+::1 localhost
10.0.0.5 db
Plan: 1 to revert, 0 not reverted, as root.
Do you want to revert these changes? Only 'yes' will be accepted.
Enter a value: yes
Results:
applied /etc/hosts
Recorded as generation 3 (complete): reverted to 1.
Approved: yes typed at a terminal.
The pass after it recorded generation 4.Right before replacing each file, the server checks that the file still has the content the preview showed, and refuses it otherwise: a file edited by someone else in between is reported as changed since the preview, never overwritten. A revert of sshd’s configuration, sudoers, PAM or firewall files runs as a trial that the server undoes by itself unless you confirm it after a fresh login. See the revert reference.
Run lemano --help for every command and the exit codes.
Next
- Reading the history: the generations, passes and objects Lemano keeps
- Running on a schedule and seeing what changed every day
- Using your SSH config: aliases, jump hosts and keys you already have
- Reverting: what a revert writes and how a trial protects you
- Lemano and Ansible: your inventory, your playbooks and your roles