ops: rescue sshd: correct passwd, pkill pattern that cannot match its caller; verified in an isolated namespace (login + pty)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
c7d638c8a4
commit
221801b34d
@@ -50,9 +50,9 @@ copy_bin() { # copy a binary and its shared libraries into the chroot, same pat
|
||||
}
|
||||
|
||||
teardown() {
|
||||
pkill -f "sshd_config -E /rescue.log" 2>/dev/null || true
|
||||
pkill -f "sshd_config -E /[r]escue.log" 2>/dev/null || true
|
||||
sleep 1
|
||||
pkill -9 -f "sshd_config -E /rescue.log" 2>/dev/null || true
|
||||
pkill -9 -f "sshd_config -E /[r]escue.log" 2>/dev/null || true
|
||||
local t
|
||||
while read -r t; do mount --make-rprivate "$t" 2>/dev/null || true; done < <(awk -v r="$R" 'index($2, r)==1 {print $2}' /proc/mounts)
|
||||
while read -r t; do umount -l "$t" 2>/dev/null || true; done < <(awk -v r="$R" 'index($2, r)==1 {print $2}' /proc/mounts | sort -r)
|
||||
@@ -76,9 +76,8 @@ build() {
|
||||
chroot "$R" /usr/bin/busybox --install -s /bin 2>/dev/null || { for a in ls cat dmesg ps free df sync mount umount dd grep tail head sleep sh sysctl; do ln -sf /usr/bin/busybox "$R/bin/$a"; done; }
|
||||
ln -sf /usr/bin/bash "$R/bin/bash"
|
||||
# identity and keys (copied once, no disk access later)
|
||||
getent passwd root sshd > "$R/etc/passwd"
|
||||
sed -i 's|^root:\([^:]*\):\([^:]*\):\([^:]*\):\([^:]*\):[^:]*:[^:]*$|root:::::/root:/bin/bash|' "$R/etc/passwd"
|
||||
getent group root nogroup sshd > "$R/etc/group" 2>/dev/null || true
|
||||
{ echo 'root:x:0:0:root:/root:/bin/bash'; getent passwd sshd; } > "$R/etc/passwd"
|
||||
{ echo 'root:x:0:'; getent group nogroup sshd; } > "$R/etc/group" 2>/dev/null || true
|
||||
printf 'passwd: files
|
||||
group: files
|
||||
shadow: files
|
||||
@@ -154,7 +153,7 @@ WantedBy=multi-user.target
|
||||
EOF
|
||||
systemctl daemon-reload; systemctl enable leleka-rescue-sshd.service; systemctl restart leleka-rescue-sshd.service ;;
|
||||
check)
|
||||
pid=$(pgrep -f "sshd_config -E /rescue.log" | head -1)
|
||||
pid=$(pgrep -f "sshd_config -E /[r]escue.log" | head -1)
|
||||
[ -n "$pid" ] || { echo "rescue sshd is not running"; exit 1; }
|
||||
echo "rescue sshd pid $pid; files it maps or holds open outside tmpfs/proc/dev (must be empty):"
|
||||
{ awk '{print $6}' /proc/$pid/maps | grep '^/' | sort -u; ls -l /proc/$pid/fd | awk '{print $NF}' | grep '^/' | sort -u; } \
|
||||
|
||||
@@ -16,7 +16,7 @@ S=${1:-600}
|
||||
if [ "$(id -u)" -ne 0 ]; then echo "run as root (sudo)" >&2; exit 1; fi
|
||||
case "$S" in ''|*[!0-9]*) echo "seconds must be a number" >&2; exit 2;; esac
|
||||
[ "$S" -ge 60 ] && [ "$S" -le 1800 ] || { echo "seconds must be 60..1800" >&2; exit 2; }
|
||||
pgrep -f "^/usr/sbin/sshd -D -e -f /etc/ssh/sshd_config -E /rescue.log" >/dev/null || { echo "rescue sshd is not running: run rescue-sshd.sh --build first" >&2; exit 1; }
|
||||
pgrep -f "sshd_config -E /[r]escue.log" >/dev/null || { echo "rescue sshd is not running: run rescue-sshd.sh --build first" >&2; exit 1; }
|
||||
command -v fsfreeze >/dev/null || { echo "fsfreeze not found" >&2; exit 1; }
|
||||
cp "$(command -v fsfreeze)" /run/rescue/bin/fsfreeze 2>/dev/null || true # so the rescue shell can thaw by hand (its libs are already there for most libc-only tools)
|
||||
for m in /data /; do
|
||||
|
||||
Reference in New Issue
Block a user