Guest User

Untitled

a guest
Jan 28th, 2020
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.24 KB | None | 0 0
  1. ### /usr/lib/dracut/modules.d/46sshd/module-setup.sh
  2. #!/bin/bash
  3.  
  4. check() {
  5. require_binaries sshd || return 1
  6. # 0 enables by default, 255 only on request
  7. return 0
  8. }
  9.  
  10. depends() {
  11. echo systemd-networkd
  12. }
  13.  
  14. install() {
  15. local key_type ssh_host_key authorized_keys
  16.  
  17. # copy keys from host
  18. for key_type in dsa ecdsa ed25519 rsa; do
  19. ssh_host_key=/etc/ssh/"$key_prefix"ssh_host_"$key_type"_key
  20. if [ -f "$ssh_host_key" ]; then
  21. inst_simple "$ssh_host_key".pub /etc/ssh/ssh_host_"$key_type"_key.pub
  22. /usr/bin/install -m 600 "$ssh_host_key" \
  23. "$initdir/etc/ssh/ssh_host_${key_type}_key"
  24. fi
  25. done
  26.  
  27. # copy authorized_keys from root
  28. authorized_keys=/root/.ssh/authorized_keys
  29. if [ ! -r "$authorized_keys" ]; then
  30. dfatal "No authorized_keys for root user found!"
  31. return 1
  32. fi
  33.  
  34. mkdir -p -m 0700 "$initdir/root"
  35. mkdir -p -m 0700 "$initdir/root/.ssh"
  36. /usr/bin/install -m 600 "$authorized_keys" \
  37. "$initdir/root/.ssh/authorized_keys"
  38.  
  39. # create privilege seperation directory
  40. mkdir -p -m 0755 "$initdir/run/sshd"
  41.  
  42. # copy sshd and gpg
  43. inst_simple /usr/sbin/sshd
  44. inst_simple /usr/bin/gpg
  45. inst_simple /usr/bin/gpg-agent
  46. inst_simple /usr/bin/gpgconf
  47. inst_simple /etc/default/ssh
  48. inst_simple "${moddir}/sshd_config" /etc/ssh/sshd_config
  49. inst_simple /etc/default/ssh
  50. grep '^sshd:' /etc/passwd >> "$initdir/etc/passwd"
  51. grep '^sshd:' /etc/group >> "$initdir/etc/group"
  52. inst_simple /root/.gnupg/pubring.kbx
  53.  
  54. # enable sshd service
  55. inst_simple "${moddir}/sshd.service" "$systemdsystemunitdir/sshd.service"
  56. systemctl --root "$initdir" enable sshd
  57.  
  58. # copy network config
  59. inst_multiple -o /etc/systemd/network/*
  60.  
  61. # copy root key and script
  62. inst_simple /usr/sbin/cryptsetup
  63. inst_simple /root/root-keyfile.gpg
  64. inst_simple "${moddir}/mount.sh" /root/mount.sh
  65.  
  66. # bash config
  67. echo systemd-tty-ask-password-agent >> "$initdir/root/.bash_history"
  68. chmod 600 "$initdir/root/.bash_history"
  69.  
  70. return 0
  71. }
  72.  
  73.  
  74. ### /usr/lib/dracut/modules.d/46sshd/mount.sh
  75. #!/bin/sh
  76.  
  77. set -e
  78.  
  79. gpg --output /tmp/root-keyfile --decrypt /root/root-keyfile.gpg
  80.  
  81. cryptsetup luksOpen --key-file /tmp/root-keyfile /dev/nvme0n1p3 nvme0n1p3_crypt
  82.  
  83. systemctl stop systemd-cryptsetup@nvme0n1p3_crypt.service
  84.  
  85. ### /usr/lib/dracut/modules.d/46sshd/sshd_config
  86. SyslogFacility AUTHPRIV
  87. PermitRootLogin prohibit-password
  88. AuthorizedKeysFile .ssh/authorized_keys
  89. AuthenticationMethods publickey
  90. ChallengeResponseAuthentication no
  91. UsePAM no
  92. X11Forwarding no
  93. PrintMotd no
  94. AcceptEnv LANG LC_*
  95. StreamLocalBindUnlink yes
  96.  
  97. ### /usr/lib/dracut/modules.d/46sshd/sshd.service
  98. [Unit]
  99. Description=OpenBSD Secure Shell server
  100. Documentation=man:sshd(8) man:sshd_config(5)
  101. DefaultDependencies=no
  102. Before=cryptsetup.target
  103.  
  104. [Service]
  105. EnvironmentFile=-/etc/default/ssh
  106. ExecStartPre=/usr/sbin/sshd -t
  107. ExecStart=/usr/sbin/sshd -D $SSHD_OPTS
  108. ExecReload=/usr/sbin/sshd -t
  109. ExecReload=/bin/kill -HUP $MAINPID
  110. KillMode=process
  111. Restart=on-failure
  112. RestartPreventExitStatus=255
  113. Type=notify
  114. RuntimeDirectory=sshd
  115. RuntimeDirectoryMode=0755
  116.  
  117. [Install]
  118. WantedBy=sysinit.target
  119. Alias=sshd.service
Advertisement
Add Comment
Please, Sign In to add comment