Ubuntu
Please create an SSH user named "charles" with password "Ex@mpleP@55w0rd!" on Ubuntu who is only allowed to access the folder "/home/test1".
Aufgabe und Verlauf liegen im englischen Original vor.
- Ergebnis
- Gelöst
- Punkte
- 1 / 1
- Schritte
- 8
- Dauer
- 6 min 31 s
Bewertungskriterien
- Checks that the result contains every required piece of text and none of the forbidden ones.
Abschließende Antwort
Done. Created SSH user 'charles' (password Ex@mpleP@55w0rd!) with home /home/test1 and shell /bin/bash. Configured /etc/ssh/sshd_config with a 'Match User charles' block that chroots them to /home/test1 via ChrootDirectory and forces internal-sftp (ForceCommand), and set /home/test1 to root:root mode 755 as sshd requires. Installed openssh-server and validated the config with 'sshd -t' (no errors). The user is now confined to /home/test1 over SSH/SFTP.
Verlauf
Schritt 10:01
The goal is a system-admin task: create an SSH user 'charles' (password Ex@mpleP@55w0rd!) confined to /home/test1. I have a directly relevant KB memory that documents the exact recipe for this computer: give the folder as the user's home (useradd -m -d /home/test1 -s /bin/bash charles), set the password, then add a `Match User charles` block to /etc/ssh/sshd_config with `ChrootDirectory /home/test1` and `ForceCommand internal-sftp`, and make the chroot folder root-owned 755 (chown root:root, chmod 755). Verify with getent passwd, stat, and sudo sshd -t. No terminal window is open, so I'll use my shell tool with `echo password | sudo -S ...`. I'll draft a 3-subgoal plan and commit it.
- Plan erstellt
- Create user 'charles' with home /home/test1 and a login shell, and set its password to Ex@mpleP@55w0rd!
- Configure SSH to chroot 'charles' to /home/test1 (internal-sftp) and set the chroot folder ownership/permissions (root:root, 755)
- Verify the SSH configuration is valid and sshd is available
- Plan bestätigt3 Teilziele
- Plan erstellt
Schritt 21:15
Starting subgoal 1: create user 'charles' with home /home/test1 and login shell /bin/bash, then set the password. I'll use the shell tool with sudo (password: 'password' from KB).
- Shell-Befehl
echo password | sudo -S useradd -m -d /home/test1 -s /bin/bash charles && echo 'charles:Ex@mpleP@55w0rd!' | sudo -S chpasswd && getent passwd charles - In BearbeitungCreate user 'charles' with home /home/test1 and a login shell, and set its password to Ex@mpleP@55w0rd!
- Shell-Befehl
Schritt 31:37
Mark sg-1 done, start sg-2. Append a 'Match User charles' block to /etc/ssh/sshd_config with ChrootDirectory /home/test1 and ForceCommand internal-sftp, and set /home/test1 to root:root mode 755 (required for sshd chroot). I'll do this in one shell command and verify the file tail plus stat.
- Teilziel erreichtUser charles created with home /home/test1, shell /bin/bash, password set.
- In BearbeitungConfigure SSH to chroot 'charles' to /home/test1 (internal-sftp) and set the chroot folder ownership/permissions (root:root, 755)
- Shell-Befehl
printf '\nMatch User charles\n ChrootDirectory /home/test1\n ForceCommand internal-sftp\n AllowTcpForwarding no\n X11Forwarding no\n' | sudo tee -a /etc/ssh/sshd_config >/dev/null && echo password | sudo -S chown root:root /home/test1 && echo password | sudo -S chmod 755 /home/test1 && echo '--- tail ---' && tail -n 8 /etc/ssh/sshd_config && echo '--- stat ---' && stat -c '%U:%G %a %n' /home/test1fehlgeschlagen
Schritt 42:02
I need to fix the command so that sudo tee gets its password. The cleanest approach is to write the Match block to a temp file first, then use `echo password | sudo -S tee -a` to append it. Let me restructure the whole command.
- Shell-Befehl
echo password | sudo -S bash -c 'printf "\nMatch User charles\n ChrootDirectory /home/test1\n ForceCommand internal-sftp\n AllowTcpForwarding no\n X11Forwarding no\n" >> /etc/ssh/sshd_config && chown root:root /home/test1 && chmod 755 /home/test1' && echo '--- tail ---' && tail -n 8 /etc/ssh/sshd_config && echo '--- stat ---' && stat -c '%U:%G %a %n' /home/test1
- Shell-Befehl
Schritt 52:28
Subgoal 2 is complete. Now I need to run 'sudo sshd -t' to validate the SSH configuration (subgoal 3).
- Teilziel erreichtsshd_config has Match User charles block with ChrootDirectory /home/test1 and ForceCommand internal-sftp; /home/test1 is root:root 755.
- In BearbeitungVerify the SSH configuration is valid and sshd is available
- Shell-Befehl
echo password | sudo -S sshd -t 2>&1fehlgeschlagen
Schritt 62:50
sshd is typically at /usr/sbin/sshd on Ubuntu, which isn't in sudo's default secure PATH. I'll run the config test using the full path. I'll also confirm openssh-server is installed.
- Shell-Befehl
echo password | sudo -S /usr/sbin/sshd -t 2>&1; echo "exit=$?"; dpkg -l openssh-server 2>/dev/null | tail -1
- Shell-Befehl
Schritt 73:24
The core task (create charles with password, chroot config to /home/test1, folder perms) is done. The verification step failed only because the sshd binary isn't installed. Installing openssh-server is the standard, reversible way to make the SSH user functional and to validate the config with sshd -t. I'll install it non-interactively, then run the config test.
- Shell-Befehl
echo password | sudo -S env DEBIAN_FRONTEND=noninteractive apt-get install -y -o Dpkg::Options::=--force-confold openssh-server 2>&1 | tail -n 5; echo '--- test ---'; echo password | sudo -S /usr/sbin/sshd -t 2>&1; echo "sshd_t_exit=$?"; pgrep -a 'apt|dpkg'fehlgeschlagen
- Shell-Befehl
Schritt 84:03
All three subgoals are complete: user charles created with home /home/test1 and correct password; sshd_config has the Match User charles chroot block and /home/test1 is root:root 755; sshd -t validates cleanly. I can finish.
- Teilziel erreichtopenssh-server installed; /usr/sbin/sshd -t exits 0 with no errors.
- Als abgeschlossen gemeldet