A tool for managing ssh authorized_key files on servers
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2022-07-24 08:36:28 -05:00
.github/workflows refactor: use cli args for configuration 2022-07-23 14:23:30 -05:00
hack/tests refactor: use cli args for configuration 2022-07-23 14:23:30 -05:00
internal output: fix destination file for when running in systemd 2022-07-24 08:31:58 -05:00
.gitignore gh-10 : update all the things 2019-07-20 20:10:49 -05:00
go.mod refactor: remove generate line for mock 2022-07-23 14:26:24 -05:00
go.sum refactor: use cli args for configuration 2022-07-23 14:23:30 -05:00
LICENSE Initial commit 2017-12-17 23:31:51 -06:00
main.go output: fix destination file for when running in systemd 2022-07-24 08:31:58 -05:00
README.md docs: update readme no more home flag 2022-07-24 08:36:28 -05:00

ssh-key-sync

Command ssh-key-sync is a tool for managing authorized_key files, by synchronizing the contents with public keys managed by accounts on GitHub.

CI GitHub

Project Overview

Module github.com/shoenig/ssh-key-sync provides the command ssh-key-sync.

Getting Started

The ssh-key-sync command can be installed by running

go install github.com/shoenig/ssh-key-sync@v1.4.1

Example Usage

There are a few arguments, but typically you should only need to specify --github-user. The Linux user and authorized_key file are by default assumed to be of the user running the command.

ssh-key-sync --github-user <user>

Configuration

ssh-key-sync -help
Usage of ./ssh-key-sync:
  -authorized-keys string
    	override the output authorized_keys file (default "/home/$USER/.ssh/authorized_keys")
  -github-api string
    	specify the GitHub API endpoint (default "https://api.github.com")
  -github-user string
    	specify the github user
  -system-user string
    	specify the unix system user (default "$USER")
  -verbose
    	print verbose logging

Systemd Timer

A great way to keep your authorized_key file up-to-date is to run ssh-key-sync periodically via a systemd timer. To set this up, we will need two files - one service file which represents execution of ssh-key-sync, and a timer file which represents the schedule on which the service should be executed. Use the example below, modifying paths to suite your needs. More examples can be found in this blog post.

The service file /etc/systemd/system/ssh-key-sync.service
[Unit]
Description=Synchronize ssh authorized keys with public keys from github.

[Service]
ExecStart=/opt/bin/ssh-key-sync -verbose -system-user <user> -github-user <user>
The timer file /etc/systemd/system/ssh-key-sync.timer
[Unit]
Description=Run ssk-key-sync every hour

[Timer]
OnBootSec=5min
OnUnitActiveSec=1h
Unit=ssh-key-sync.service

[Install]
WantedBy=timers.target
Enable the timer
$ systemctl enable ssh-key-sync.timer

Contributing

The github.com/shoenig/ssh-key-sync tool is always improving with new features and error corrections. For contributing bug fixes and new features please file an issue.

License

MIT