-
Notifications
You must be signed in to change notification settings - Fork 4
Home
Sly edited this page May 8, 2022
·
4 revisions
Welcome to the FreeDomains wiki!
An unknown issue is wiping out the public keys inside /home/git/.ssh/authorized_keys
file. A Temporary solution is to ssh into the server and execute this script to copy over the keys from the data.db
file.
// /root/authorizedKeys.js
1 #!/usr/bin/env node
2
3 const fs = require('fs')
4
5 const AUTHORIZED_KEYS_PATH = '/home/git/.ssh/authorized_keys'
6 const DATA_DB_PATH = '/home/myproxy/freedomains.dev/data.db'
7
8 fs.readFile(DATA_DB_PATH, (err, buffer) => {
9
10 if (err) return console.log(err)
11
12 const {users} = JSON.parse(buffer+'')
13
14 if (!users) return console.log('No users found, aborting.')
15
16 console.log("Restoring users' ssh keys")
17
18 const keys = Object.values(users).reduce(
19 (acc, key) => acc + "\n" + key
20 , "")
21
22 fs.writeFile(AUTHORIZED_KEYS_PATH, keys, (error) => {
23 if (error) return console.log(error)
24
25 // change to git user id/group id (found with 'id git' in terminal)
26 fs.chown(AUTHORIZED_KEYS_PATH, 1001, 1001, (error) => {
27 if (error) console.log(error)
28
29 console.log(`keys successfully restored: ${AUTHORIZED_KEYS_PATH}`)
30 })
31 })
32 })
A cronjob was added, the script will run every day at midnight.
0 0 * * * /usr/bin/sh /root/authorizedKeys.js >/dev/null 2>&1