Kaynağa Gözat

Documentation and configuration file

Laurent HUBERT 6 yıl önce
ebeveyn
işleme
aa4db7ff62
7 değiştirilmiş dosya ile 131 ekleme ve 4 silme
  1. 1 0
      .gitignore
  2. 121 2
      README.md
  3. 0 1
      deploy
  4. 1 1
      first-boot-init.service
  5. 2 0
      first-boot-script
  6. 3 0
      scripts/90-display-ip
  7. 3 0
      sync.data.example

+ 1 - 0
.gitignore

@@ -1 +1,2 @@
 dosync.sh
+sync.data

+ 121 - 2
README.md

@@ -1,9 +1,128 @@
-# systemd-first-boot-script
+# Introduction
+
+`systemd-first-boot-script` is a set of scripts to configure GNU+Linux systems at first boot.
+
+## Purpose
+
+Setting up pre-configured virtual machines or GNU+Linux system is easy. Sharing them to other people involves sharing credentials, which is not a good thing from security point of view.
+
+This set of scripts allows running several configuration programs in order to:
+
+- reset SSH server keys
+- change root password
+- change main user password (which is supposed to be in sudoers group)
+- create a new user within sudoers group
+- change machine name
+- display connection information (or anything else)
+
+A skeleton is provided to create one's own scripts.
+
+## Deployment
+
+The target machine should have a working `ssh` server.
+
+The preparation of script is done on another machine (local machine e.g.) from which the script can be sent using a synchronization script.
+
+Actually, this prevent from installing `git` on the target machine (which is not wanted for some systems).
+
+# Installation and configuration
+
+Clone this directory on your local machine.
+
+## Configuration
+
+Copy `sync.data.example` to `sync.data` :
+
+```bash
+cp sync.data.example sync.data
+```
+
+Edit `sync.data` with credential for target machine (using `ssh` keys is recommended but not mandatory).
+
+## Deployment
+
+### Remote copy
+
+Run synchronization script from local machine:
+
+```bash
+./dosync.sh
+```
+
+All files should be copied on the target machine
+
+### On target machine
+
+Everything here should be run as super-user (or with `sudo`).
+
+From the synced directory, run the deployment script:
+
+```bash
+cd install-systemd-first-boot-script # or the name you chose in sync.data
+./deploy
+```
+
+All files are copied to `/etc/first-boot/`
+
+Select the files to be executed in `/etc/first-boot/scripts` (here is selected a subset of available scripts) :
+
+```bash
+cd /etc/first-boot/scripts
+chmod -x *
+chmod +x 01-renew-ssh-keys 02-password 03-user-password 50-hostname
+```
+
+Check the permissions are correct (only scripts with execution permission will be run):
+
+```bash
+ls -l /etc/first-boot/scripts
+-rwxr-xr-x@ 1 root  root   625 10 oct 10:59 01-renew-ssh-keys
+-rwxr-xr-x@ 1 root  root   581 10 oct 10:59 02-password
+-rwxr-xr-x@ 1 root  root   662 10 oct 11:01 03-user-password
+-rw-r--r--@ 1 root  root  1114 10 oct 11:08 04-create-default-user
+-rwxr-xr-x  1 root  root   660 10 oct 11:09 50-hostname
+-rw-r--r--@ 1 root  root   732 11 oct 15:42 90-display-ip
+-rw-r--r--@ 1 root  root   755 10 oct 10:59 skeleton
+```
+
+Now the machine is ready to be rebooted.
+
+### Test
+
+You can test by rebooting the machine.
+
+You will have to answer to all question (it is not possible to kill process). So use passwords you know.
+
+Once is is OK for you, re-run the deployment script (this will reset the flag that indicates the script was already run):
+
+```bash
+cd install-systemd-first-boot-script # or the name you chose in sync.data
+./deploy
+```
+
+And check once again the permissions in `/etc/first-boot/scripts` (just to be sure, even they should not have been changed)
+
+You can now delete the installation directory (which could be recreated using the `dosync.sh` script from your local machine :
+
+```bash
+cd ..
+rm -r install-systemd-first-boot-script
+```
+
+## Use it
+
+### Strong passwords
+
+Don't forget to use strong passwords on your systems
+
+### Share your work
+
+Once ready, shutdown the system and provide it to the person who will use it: this person will have to set its own passwords at first boot.
 
-A skeleton for GNU+Linux system first boot configuration
 
 # References
 
+- [How to start a script on tty instead of asking for login in systemd? - Unix & Linux Stack Exchange](https://unix.stackexchange.com/questions/265014/how-to-start-a-script-on-tty-instead-of-asking-for-login-in-systemd)
 - [ubuntu - Run script on first boot - Server Fault](https://serverfault.com/a/853403/139286)
 - [How To Use Systemctl to Manage Systemd Services and Units | DigitalOcean](https://www.digitalocean.com/community/tutorials/how-to-use-systemctl-to-manage-systemd-services-and-units)
 - [How to Create and Run New Service Units in Systemd Using Shell Script](https://www.tecmint.com/create-new-service-units-in-systemd/)

+ 0 - 1
deploy

@@ -19,7 +19,6 @@ cp scripts/* $FIRST_BOOT_SCRIPTS_DIR
 touch $FIRST_BOOT_BASE_DIR/.mustrun
 
 # Deploys
-# See https://unix.stackexchange.com/questions/265014/how-to-start-a-script-on-tty-instead-of-asking-for-login-in-systemd
 systemctl enable first-boot-init.service
 
 echo "You can now run rm -r on this directory"

+ 1 - 1
first-boot-init.service

@@ -6,7 +6,7 @@ Conflicts=getty@tty1.service
 
 [Service]
 Type=oneshot
-RemainAfterExit=yes
+RemainAfterExit=no
 ExecStart=/etc/first-boot/first-boot-script
 StandardInput=tty-force
 StandardOutput=inherit

+ 2 - 0
first-boot-script

@@ -50,4 +50,6 @@ cat <<EOF
 ###############################################
 EOF
 
+# Starts tty1 after that script is finished
+systemctl start getty@tty1.service
 exit 0

+ 3 - 0
scripts/90-display-ip

@@ -16,5 +16,8 @@ following information:
         IPv6: $IP_V6_VALUE
  sudoer user: $MAIN_USER_VALUE
 
+Press Enter to proceed
 °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°
 EOF
+read whatever
+exit 0

+ 3 - 0
sync.data.example

@@ -0,0 +1,3 @@
+EXPORT_SERVER=username@server-ip-or-name
+TARGET_DIR=install-systemd-first-boot-script
+REMOTE_DESTINATION=${EXPORT_SERVER}:'~/'${TARGET_DIR}