ssh.scm 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2014, 2015, 2016, 2017, 2018 Ludovic Courtès <ludo@gnu.org>
  3. ;;; Copyright © 2016 David Craven <david@craven.ch>
  4. ;;; Copyright © 2016 Julien Lepiller <julien@lepiller.eu>
  5. ;;; Copyright © 2017 Clément Lassieur <clement@lassieur.org>
  6. ;;; Copyright © 2019 Ricardo Wurmus <rekado@elephly.net>
  7. ;;;
  8. ;;; This file is part of GNU Guix.
  9. ;;;
  10. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  11. ;;; under the terms of the GNU General Public License as published by
  12. ;;; the Free Software Foundation; either version 3 of the License, or (at
  13. ;;; your option) any later version.
  14. ;;;
  15. ;;; GNU Guix is distributed in the hope that it will be useful, but
  16. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. ;;; GNU General Public License for more details.
  19. ;;;
  20. ;;; You should have received a copy of the GNU General Public License
  21. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  22. (define-module (gnu services ssh)
  23. #:use-module (gnu packages ssh)
  24. #:use-module (gnu packages admin)
  25. #:use-module (gnu services)
  26. #:use-module (gnu services shepherd)
  27. #:use-module (gnu system pam)
  28. #:use-module (gnu system shadow)
  29. #:use-module (guix gexp)
  30. #:use-module (guix records)
  31. #:use-module (guix modules)
  32. #:use-module (srfi srfi-1)
  33. #:use-module (srfi srfi-26)
  34. #:use-module (ice-9 match)
  35. #:export (lsh-configuration
  36. lsh-configuration?
  37. lsh-service
  38. lsh-service-type
  39. openssh-configuration
  40. openssh-configuration?
  41. openssh-service-type
  42. dropbear-configuration
  43. dropbear-configuration?
  44. dropbear-service-type
  45. dropbear-service))
  46. ;;; Commentary:
  47. ;;;
  48. ;;; This module implements secure shell (SSH) services.
  49. ;;;
  50. ;;; Code:
  51. (define-record-type* <lsh-configuration>
  52. lsh-configuration make-lsh-configuration
  53. lsh-configuration?
  54. (lsh lsh-configuration-lsh
  55. (default lsh))
  56. (daemonic? lsh-configuration-daemonic?)
  57. (host-key lsh-configuration-host-key)
  58. (interfaces lsh-configuration-interfaces)
  59. (port-number lsh-configuration-port-number)
  60. (allow-empty-passwords? lsh-configuration-allow-empty-passwords?)
  61. (root-login? lsh-configuration-root-login?)
  62. (syslog-output? lsh-configuration-syslog-output?)
  63. (pid-file? lsh-configuration-pid-file?)
  64. (pid-file lsh-configuration-pid-file)
  65. (x11-forwarding? lsh-configuration-x11-forwarding?)
  66. (tcp/ip-forwarding? lsh-configuration-tcp/ip-forwarding?)
  67. (password-authentication? lsh-configuration-password-authentication?)
  68. (public-key-authentication? lsh-configuration-public-key-authentication?)
  69. (initialize? lsh-configuration-initialize?))
  70. (define %yarrow-seed
  71. "/var/spool/lsh/yarrow-seed-file")
  72. (define (lsh-initialization lsh host-key)
  73. "Return the gexp to initialize the LSH service for HOST-KEY."
  74. #~(begin
  75. (unless (file-exists? #$%yarrow-seed)
  76. (system* (string-append #$lsh "/bin/lsh-make-seed")
  77. "--sloppy" "-o" #$%yarrow-seed))
  78. (unless (file-exists? #$host-key)
  79. (mkdir-p (dirname #$host-key))
  80. (format #t "creating SSH host key '~a'...~%" #$host-key)
  81. ;; FIXME: We're just doing a simple pipeline, but 'system' cannot be
  82. ;; used yet because /bin/sh might be dangling; factorize this somehow.
  83. (let* ((in+out (pipe))
  84. (keygen (primitive-fork)))
  85. (case keygen
  86. ((0)
  87. (close-port (car in+out))
  88. (close-fdes 1)
  89. (dup2 (fileno (cdr in+out)) 1)
  90. (execl (string-append #$lsh "/bin/lsh-keygen")
  91. "lsh-keygen" "--server"))
  92. (else
  93. (let ((write-key (primitive-fork)))
  94. (case write-key
  95. ((0)
  96. (close-port (cdr in+out))
  97. (close-fdes 0)
  98. (dup2 (fileno (car in+out)) 0)
  99. (execl (string-append #$lsh "/bin/lsh-writekey")
  100. "lsh-writekey" "--server" "-o" #$host-key))
  101. (else
  102. (close-port (car in+out))
  103. (close-port (cdr in+out))
  104. (waitpid keygen)
  105. (waitpid write-key))))))))))
  106. (define (lsh-activation config)
  107. "Return the activation gexp for CONFIG."
  108. #~(begin
  109. (use-modules (guix build utils))
  110. (mkdir-p "/var/spool/lsh")
  111. #$(if (lsh-configuration-initialize? config)
  112. (lsh-initialization (lsh-configuration-lsh config)
  113. (lsh-configuration-host-key config))
  114. #t)))
  115. (define (lsh-shepherd-service config)
  116. "Return a <shepherd-service> for lsh with CONFIG."
  117. (define lsh (lsh-configuration-lsh config))
  118. (define pid-file (lsh-configuration-pid-file config))
  119. (define pid-file? (lsh-configuration-pid-file? config))
  120. (define daemonic? (lsh-configuration-daemonic? config))
  121. (define interfaces (lsh-configuration-interfaces config))
  122. (define lsh-command
  123. (append
  124. (cons (file-append lsh "/sbin/lshd")
  125. (if daemonic?
  126. (let ((syslog (if (lsh-configuration-syslog-output? config)
  127. '()
  128. (list "--no-syslog"))))
  129. (cons "--daemonic"
  130. (if pid-file?
  131. (cons #~(string-append "--pid-file=" #$pid-file)
  132. syslog)
  133. (cons "--no-pid-file" syslog))))
  134. (if pid-file?
  135. (list #~(string-append "--pid-file=" #$pid-file))
  136. '())))
  137. (cons* #~(string-append "--host-key="
  138. #$(lsh-configuration-host-key config))
  139. #~(string-append "--password-helper=" #$lsh "/sbin/lsh-pam-checkpw")
  140. #~(string-append "--subsystems=sftp=" #$lsh "/sbin/sftp-server")
  141. "-p" (number->string (lsh-configuration-port-number config))
  142. (if (lsh-configuration-password-authentication? config)
  143. "--password" "--no-password")
  144. (if (lsh-configuration-public-key-authentication? config)
  145. "--publickey" "--no-publickey")
  146. (if (lsh-configuration-root-login? config)
  147. "--root-login" "--no-root-login")
  148. (if (lsh-configuration-x11-forwarding? config)
  149. "--x11-forward" "--no-x11-forward")
  150. (if (lsh-configuration-tcp/ip-forwarding? config)
  151. "--tcpip-forward" "--no-tcpip-forward")
  152. (if (null? interfaces)
  153. '()
  154. (map (cut string-append "--interface=" <>)
  155. interfaces)))))
  156. (define requires
  157. (if (and daemonic? (lsh-configuration-syslog-output? config))
  158. '(networking syslogd)
  159. '(networking)))
  160. (list (shepherd-service
  161. (documentation "GNU lsh SSH server")
  162. (provision '(ssh-daemon))
  163. (requirement requires)
  164. (start #~(make-forkexec-constructor (list #$@lsh-command)))
  165. (stop #~(make-kill-destructor)))))
  166. (define (lsh-pam-services config)
  167. "Return a list of <pam-services> for lshd with CONFIG."
  168. (list (unix-pam-service
  169. "lshd"
  170. #:allow-empty-passwords?
  171. (lsh-configuration-allow-empty-passwords? config))))
  172. (define lsh-service-type
  173. (service-type (name 'lsh)
  174. (description
  175. "Run the GNU@tie{}lsh secure shell (SSH) daemon,
  176. @command{lshd}.")
  177. (extensions
  178. (list (service-extension shepherd-root-service-type
  179. lsh-shepherd-service)
  180. (service-extension pam-root-service-type
  181. lsh-pam-services)
  182. (service-extension activation-service-type
  183. lsh-activation)))))
  184. (define* (lsh-service #:key
  185. (lsh lsh)
  186. (daemonic? #t)
  187. (host-key "/etc/lsh/host-key")
  188. (interfaces '())
  189. (port-number 22)
  190. (allow-empty-passwords? #f)
  191. (root-login? #f)
  192. (syslog-output? #t)
  193. (pid-file? #f)
  194. (pid-file "/var/run/lshd.pid")
  195. (x11-forwarding? #t)
  196. (tcp/ip-forwarding? #t)
  197. (password-authentication? #t)
  198. (public-key-authentication? #t)
  199. (initialize? #t))
  200. "Run the @command{lshd} program from @var{lsh} to listen on port @var{port-number}.
  201. @var{host-key} must designate a file containing the host key, and readable
  202. only by root.
  203. When @var{daemonic?} is true, @command{lshd} will detach from the
  204. controlling terminal and log its output to syslogd, unless one sets
  205. @var{syslog-output?} to false. Obviously, it also makes lsh-service
  206. depend on existence of syslogd service. When @var{pid-file?} is true,
  207. @command{lshd} writes its PID to the file called @var{pid-file}.
  208. When @var{initialize?} is true, automatically create the seed and host key
  209. upon service activation if they do not exist yet. This may take long and
  210. require interaction.
  211. When @var{initialize?} is false, it is up to the user to initialize the
  212. randomness generator (@pxref{lsh-make-seed,,, lsh, LSH Manual}), and to create
  213. a key pair with the private key stored in file @var{host-key} (@pxref{lshd
  214. basics,,, lsh, LSH Manual}).
  215. When @var{interfaces} is empty, lshd listens for connections on all the
  216. network interfaces; otherwise, @var{interfaces} must be a list of host names
  217. or addresses.
  218. @var{allow-empty-passwords?} specifies whether to accept log-ins with empty
  219. passwords, and @var{root-login?} specifies whether to accept log-ins as
  220. root.
  221. The other options should be self-descriptive."
  222. (service lsh-service-type
  223. (lsh-configuration (lsh lsh) (daemonic? daemonic?)
  224. (host-key host-key) (interfaces interfaces)
  225. (port-number port-number)
  226. (allow-empty-passwords? allow-empty-passwords?)
  227. (root-login? root-login?)
  228. (syslog-output? syslog-output?)
  229. (pid-file? pid-file?) (pid-file pid-file)
  230. (x11-forwarding? x11-forwarding?)
  231. (tcp/ip-forwarding? tcp/ip-forwarding?)
  232. (password-authentication?
  233. password-authentication?)
  234. (public-key-authentication?
  235. public-key-authentication?)
  236. (initialize? initialize?))))
  237. ;;;
  238. ;;; OpenSSH.
  239. ;;;
  240. (define-record-type* <openssh-configuration>
  241. openssh-configuration make-openssh-configuration
  242. openssh-configuration?
  243. ;; <package>
  244. (openssh openssh-configuration-openssh
  245. (default openssh))
  246. ;; string
  247. (pid-file openssh-configuration-pid-file
  248. (default "/var/run/sshd.pid"))
  249. ;; integer
  250. (port-number openssh-configuration-port-number
  251. (default 22))
  252. ;; Boolean | 'without-password
  253. (permit-root-login openssh-configuration-permit-root-login
  254. (default #f))
  255. ;; Boolean
  256. (allow-empty-passwords? openssh-configuration-allow-empty-passwords?
  257. (default #f))
  258. ;; Boolean
  259. (password-authentication? openssh-configuration-password-authentication?
  260. (default #t))
  261. ;; Boolean
  262. (public-key-authentication? openssh-configuration-public-key-authentication?
  263. (default #t))
  264. ;; Boolean
  265. (x11-forwarding? openssh-configuration-x11-forwarding?
  266. (default #f))
  267. ;; Boolean
  268. (allow-agent-forwarding? openssh-configuration-allow-agent-forwarding?
  269. (default #t))
  270. ;; Boolean
  271. (allow-tcp-forwarding? openssh-configuration-allow-tcp-forwarding?
  272. (default #t))
  273. ;; Boolean
  274. (gateway-ports? openssh-configuration-gateway-ports?
  275. (default #f))
  276. ;; Boolean
  277. (challenge-response-authentication? openssh-challenge-response-authentication?
  278. (default #f))
  279. ;; Boolean
  280. (use-pam? openssh-configuration-use-pam?
  281. (default #t))
  282. ;; Boolean
  283. (print-last-log? openssh-configuration-print-last-log?
  284. (default #t))
  285. ;; list of two-element lists
  286. (subsystems openssh-configuration-subsystems
  287. (default '(("sftp" "internal-sftp"))))
  288. ;; list of strings
  289. (accepted-environment openssh-configuration-accepted-environment
  290. (default '()))
  291. ;; symbol
  292. (log-level openssh-configuration-log-level
  293. (default 'info))
  294. ;; String
  295. ;; This is an "escape hatch" to provide configuration that isn't yet
  296. ;; supported by this configuration record.
  297. (extra-content openssh-configuration-extra-content
  298. (default ""))
  299. ;; list of user-name/file-like tuples
  300. (authorized-keys openssh-authorized-keys
  301. (default '()))
  302. ;; Boolean
  303. ;; XXX: This should really be handled in an orthogonal way, for instance as
  304. ;; proposed in <https://bugs.gnu.org/27155>. Keep it internal/undocumented
  305. ;; for now.
  306. (%auto-start? openssh-auto-start?
  307. (default #t)))
  308. (define %openssh-accounts
  309. (list (user-group (name "sshd") (system? #t))
  310. (user-account
  311. (name "sshd")
  312. (group "sshd")
  313. (system? #t)
  314. (comment "sshd privilege separation user")
  315. (home-directory "/var/run/sshd")
  316. (shell #~(string-append #$shadow "/sbin/nologin")))))
  317. (define (openssh-activation config)
  318. "Return the activation GEXP for CONFIG."
  319. (with-imported-modules '((guix build utils))
  320. #~(begin
  321. (use-modules (guix build utils))
  322. (define (touch file-name)
  323. (call-with-output-file file-name (const #t)))
  324. ;; Make sure /etc/ssh can be read by the 'sshd' user.
  325. (mkdir-p "/etc/ssh")
  326. (chmod "/etc/ssh" #o755)
  327. (mkdir-p (dirname #$(openssh-configuration-pid-file config)))
  328. ;; 'sshd' complains if the authorized-key directory and its parents
  329. ;; are group-writable, which rules out /gnu/store. Thus we copy the
  330. ;; authorized-key directory to /etc.
  331. (catch 'system-error
  332. (lambda ()
  333. (delete-file-recursively "/etc/authorized_keys.d"))
  334. (lambda args
  335. (unless (= ENOENT (system-error-errno args))
  336. (apply throw args))))
  337. (copy-recursively #$(authorized-key-directory
  338. (openssh-authorized-keys config))
  339. "/etc/ssh/authorized_keys.d")
  340. (chmod "/etc/ssh/authorized_keys.d" #o555)
  341. (let ((lastlog "/var/log/lastlog"))
  342. (when #$(openssh-configuration-print-last-log? config)
  343. (unless (file-exists? lastlog)
  344. (touch lastlog))))
  345. ;; Generate missing host keys.
  346. (system* (string-append #$(openssh-configuration-openssh config)
  347. "/bin/ssh-keygen") "-A"))))
  348. (define (authorized-key-directory keys)
  349. "Return a directory containing the authorized keys specified in KEYS, a list
  350. of user-name/file-like tuples."
  351. (define build
  352. (with-imported-modules (source-module-closure '((guix build utils)))
  353. #~(begin
  354. (use-modules (ice-9 match) (srfi srfi-26)
  355. (guix build utils))
  356. (mkdir #$output)
  357. (for-each (match-lambda
  358. ((user keys ...)
  359. (let ((file (string-append #$output "/" user)))
  360. (call-with-output-file file
  361. (lambda (port)
  362. (for-each (lambda (key)
  363. (call-with-input-file key
  364. (cut dump-port <> port)))
  365. keys))))))
  366. '#$keys))))
  367. (computed-file "openssh-authorized-keys" build))
  368. (define (openssh-config-file config)
  369. "Return the sshd configuration file corresponding to CONFIG."
  370. (computed-file
  371. "sshd_config"
  372. #~(begin
  373. (use-modules (ice-9 match))
  374. (call-with-output-file #$output
  375. (lambda (port)
  376. (display "# Generated by 'openssh-service'.\n" port)
  377. (format port "Port ~a\n"
  378. #$(number->string
  379. (openssh-configuration-port-number config)))
  380. (format port "PermitRootLogin ~a\n"
  381. #$(match (openssh-configuration-permit-root-login config)
  382. (#t "yes")
  383. (#f "no")
  384. ('without-password "without-password")))
  385. (format port "PermitEmptyPasswords ~a\n"
  386. #$(if (openssh-configuration-allow-empty-passwords? config)
  387. "yes" "no"))
  388. (format port "PasswordAuthentication ~a\n"
  389. #$(if (openssh-configuration-password-authentication? config)
  390. "yes" "no"))
  391. (format port "PubkeyAuthentication ~a\n"
  392. #$(if (openssh-configuration-public-key-authentication?
  393. config)
  394. "yes" "no"))
  395. (format port "X11Forwarding ~a\n"
  396. #$(if (openssh-configuration-x11-forwarding? config)
  397. "yes" "no"))
  398. (format port "AllowAgentForwarding ~a\n"
  399. #$(if (openssh-configuration-allow-agent-forwarding? config)
  400. "yes" "no"))
  401. (format port "AllowTcpForwarding ~a\n"
  402. #$(if (openssh-configuration-allow-tcp-forwarding? config)
  403. "yes" "no"))
  404. (format port "GatewayPorts ~a\n"
  405. #$(if (openssh-configuration-gateway-ports? config)
  406. "yes" "no"))
  407. (format port "PidFile ~a\n"
  408. #$(openssh-configuration-pid-file config))
  409. (format port "ChallengeResponseAuthentication ~a\n"
  410. #$(if (openssh-challenge-response-authentication? config)
  411. "yes" "no"))
  412. (format port "UsePAM ~a\n"
  413. #$(if (openssh-configuration-use-pam? config)
  414. "yes" "no"))
  415. (format port "PrintLastLog ~a\n"
  416. #$(if (openssh-configuration-print-last-log? config)
  417. "yes" "no"))
  418. (format port "LogLevel ~a\n"
  419. #$(string-upcase
  420. (symbol->string
  421. (openssh-configuration-log-level config))))
  422. ;; Add '/etc/authorized_keys.d/%u', which we populate.
  423. (format port "AuthorizedKeysFile \
  424. .ssh/authorized_keys .ssh/authorized_keys2 /etc/ssh/authorized_keys.d/%u\n")
  425. (for-each (lambda (s) (format port "AcceptEnv ~a\n" s))
  426. '#$(openssh-configuration-accepted-environment config))
  427. (for-each
  428. (match-lambda
  429. ((name command) (format port "Subsystem\t~a\t~a\n" name command)))
  430. '#$(openssh-configuration-subsystems config))
  431. (format port "~a\n"
  432. #$(openssh-configuration-extra-content config))
  433. #t)))))
  434. (define (openssh-shepherd-service config)
  435. "Return a <shepherd-service> for openssh with CONFIG."
  436. (define pid-file
  437. (openssh-configuration-pid-file config))
  438. (define openssh-command
  439. #~(list (string-append #$(openssh-configuration-openssh config) "/sbin/sshd")
  440. "-D" "-f" #$(openssh-config-file config)))
  441. (list (shepherd-service
  442. (documentation "OpenSSH server.")
  443. (requirement '(syslogd loopback))
  444. (provision '(ssh-daemon))
  445. (start #~(make-forkexec-constructor #$openssh-command
  446. #:pid-file #$pid-file))
  447. (stop #~(make-kill-destructor))
  448. (auto-start? (openssh-auto-start? config)))))
  449. (define (openssh-pam-services config)
  450. "Return a list of <pam-services> for sshd with CONFIG."
  451. (list (unix-pam-service
  452. "sshd"
  453. #:allow-empty-passwords?
  454. (openssh-configuration-allow-empty-passwords? config))))
  455. (define (extend-openssh-authorized-keys config keys)
  456. "Extend CONFIG with the extra authorized keys listed in KEYS."
  457. (openssh-configuration
  458. (inherit config)
  459. (authorized-keys
  460. (append (openssh-authorized-keys config) keys))))
  461. (define openssh-service-type
  462. (service-type (name 'openssh)
  463. (description
  464. "Run the OpenSSH secure shell (SSH) server, @command{sshd}.")
  465. (extensions
  466. (list (service-extension shepherd-root-service-type
  467. openssh-shepherd-service)
  468. (service-extension pam-root-service-type
  469. openssh-pam-services)
  470. (service-extension activation-service-type
  471. openssh-activation)
  472. (service-extension account-service-type
  473. (const %openssh-accounts))
  474. ;; Install OpenSSH in the system profile. That way,
  475. ;; 'scp' is found when someone tries to copy to or from
  476. ;; this machine.
  477. (service-extension profile-service-type
  478. (lambda (config)
  479. (list (openssh-configuration-openssh
  480. config))))))
  481. (compose concatenate)
  482. (extend extend-openssh-authorized-keys)
  483. (default-value (openssh-configuration))))
  484. ;;;
  485. ;;; Dropbear.
  486. ;;;
  487. (define-record-type* <dropbear-configuration>
  488. dropbear-configuration make-dropbear-configuration
  489. dropbear-configuration?
  490. (dropbear dropbear-configuration-dropbear
  491. (default dropbear))
  492. (port-number dropbear-configuration-port-number
  493. (default 22))
  494. (syslog-output? dropbear-configuration-syslog-output?
  495. (default #t))
  496. (pid-file dropbear-configuration-pid-file
  497. (default "/var/run/dropbear.pid"))
  498. (root-login? dropbear-configuration-root-login?
  499. (default #f))
  500. (allow-empty-passwords? dropbear-configuration-allow-empty-passwords?
  501. (default #f))
  502. (password-authentication? dropbear-configuration-password-authentication?
  503. (default #t)))
  504. (define (dropbear-activation config)
  505. "Return the activation gexp for CONFIG."
  506. #~(begin
  507. (use-modules (guix build utils))
  508. (mkdir-p "/etc/dropbear")))
  509. (define (dropbear-shepherd-service config)
  510. "Return a <shepherd-service> for dropbear with CONFIG."
  511. (define dropbear
  512. (dropbear-configuration-dropbear config))
  513. (define pid-file
  514. (dropbear-configuration-pid-file config))
  515. (define dropbear-command
  516. #~(list (string-append #$dropbear "/sbin/dropbear")
  517. ;; '-R' allows host keys to be automatically generated upon first
  518. ;; connection, at a time when /dev/urandom is more likely securely
  519. ;; seeded.
  520. "-F" "-R"
  521. "-p" #$(number->string (dropbear-configuration-port-number config))
  522. "-P" #$pid-file
  523. #$@(if (dropbear-configuration-syslog-output? config) '() '("-E"))
  524. #$@(if (dropbear-configuration-root-login? config) '() '("-w"))
  525. #$@(if (dropbear-configuration-password-authentication? config)
  526. '()
  527. '("-s" "-g"))
  528. #$@(if (dropbear-configuration-allow-empty-passwords? config)
  529. '("-B")
  530. '())))
  531. (define requires
  532. (if (dropbear-configuration-syslog-output? config)
  533. '(networking syslogd) '(networking)))
  534. (list (shepherd-service
  535. (documentation "Dropbear SSH server.")
  536. (requirement requires)
  537. (provision '(ssh-daemon))
  538. (start #~(make-forkexec-constructor #$dropbear-command
  539. #:pid-file #$pid-file))
  540. (stop #~(make-kill-destructor)))))
  541. (define dropbear-service-type
  542. (service-type (name 'dropbear)
  543. (description
  544. "Run the Dropbear secure shell (SSH) server.")
  545. (extensions
  546. (list (service-extension shepherd-root-service-type
  547. dropbear-shepherd-service)
  548. (service-extension activation-service-type
  549. dropbear-activation)))))
  550. (define* (dropbear-service #:optional (config (dropbear-configuration)))
  551. "Run the @uref{https://matt.ucc.asn.au/dropbear/dropbear.html,Dropbear SSH
  552. daemon} with the given @var{config}, a @code{<dropbear-configuration>}
  553. object."
  554. (service dropbear-service-type config))
  555. ;;; ssh.scm ends here