forked from fullstory/sshstart https://github.com/fullstory/sshstart
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sshactivate 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #!/bin/sh
  2. # sshstart - Start SSHD and set a password (if necessary)
  3. # Copyright (C) 2001, Klaus Knopper <knopper@knopper.net>
  4. # Copyright (C) 2004, Joerg Schirottke Jan
  5. # Copyright (C) 2004-2014, Stefan Lippers-Hollmann <s.l-h@gmx.de>
  6. # Copyright (C) 2007, Kel Modderman <kel@otaku42.de>
  7. # This program is free software; you can redistribute it and/or
  8. # modify it under the terms of the GNU General Public License
  9. # as published by the Free Software Foundation; version 2 of the
  10. # License.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. # override tool behaviour through distro-defaults
  17. FLL_LIVE_USER="siducer"
  18. if [ -s /etc/default/distro ]; then
  19. . /etc/default/distro
  20. fi
  21. if [ "$(id -u)" -ne 0 ]; then
  22. [ -x "$(which su-to-root)" ] && exec su-to-root -X -c "$0" "$@"
  23. printf "ERROR: $0 needs root capabilities, please start it as root.\n\n" >&2
  24. exit 1
  25. fi
  26. if [ ! -x /etc/init.d/ssh ]; then
  27. echo "openssh-server is not installed, aborting."
  28. exit 2
  29. fi
  30. if pgrep -x sshd >/dev/null; then
  31. echo "openssh-server is already running, aborting."
  32. exit 3
  33. fi
  34. # use keygen if needed
  35. if [ ! -e /etc/ssh/ssh_host_rsa_key ]; then
  36. echo "Generating SSH2 RSA key..."
  37. ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -C '' -N ''
  38. if which restorecon >/dev/null 2>&1; then
  39. restorecon /etc/ssh/ssh_host_rsa_key \
  40. /etc/ssh/ssh_host_rsa_key.pub
  41. fi
  42. fi
  43. if [ ! -e /etc/ssh/ssh_host_dsa_key ]; then
  44. echo "Generating SSH2 DSA key..."
  45. ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -C '' -N ''
  46. if which restorecon >/dev/null 2>&1; then
  47. restorecon /etc/ssh/ssh_host_dsa_key \
  48. /etc/ssh/ssh_host_dsa_key.pub
  49. fi
  50. fi
  51. if [ ! -e /etc/ssh/ssh_host_ecdsa_key ]; then
  52. echo "Generating SSH2 ECDSA key..."
  53. ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -C '' -N ''
  54. if which restorecon >/dev/null 2>&1; then
  55. restorecon /etc/ssh/ssh_host_ecdsa_key \
  56. /etc/ssh/ssh_host_ecdsa_key.pub
  57. fi
  58. fi
  59. if [ ! -e /etc/ssh/ssh_host_ed25519_key ]; then
  60. echo "Generating SSH2 ED25519 key..."
  61. ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -C '' -N ''
  62. if which restorecon >/dev/null 2>&1; then
  63. restorecon /etc/ssh/ssh_host_ed25519_key \
  64. /etc/ssh/ssh_host_ed25519_key.pub
  65. fi
  66. fi
  67. systemctl enable ssh
  68. systemctl start ssh
  69. if [ "$?" -ne 0 ]; then
  70. echo "openssh-server failed to start, aborting."
  71. exit 4
  72. fi
  73. until ! grep -q "^$FLL_LIVE_USER:\*:" /etc/shadow; do
  74. echo ""
  75. echo "Set password for user '$FLL_LIVE_USER'"
  76. passwd "$FLL_LIVE_USER"
  77. done
  78. echo ""
  79. echo -n "Finished. Press Enter to exit."
  80. read DUMMY
  81. exit 0