Anpassungen hinzufügen von ssh-key und anpassung der out.csv

This commit is contained in:
2025-09-26 15:51:04 +02:00
parent 55035ba890
commit 7e4ef95c37
3 changed files with 163 additions and 14 deletions

View File

@@ -44,6 +44,7 @@ def main():
parser.add_argument("password", help="Das gewünschte root-Passwort.")
parser.add_argument("hostname", help="Der Hostname für diesen Container.")
parser.add_argument("distro", help="Die Distribution des Containers (z.B. 'arch', 'ubuntu').")
parser.add_argument("ssh_key", nargs='?', default="", help="Der öffentliche SSH-Schlüssel für den Benutzer 'jonnybravo'.")
args = parser.parse_args()
root_password = args.password
@@ -132,7 +133,18 @@ def main():
wheel_group_equivalent = "wheel" if distro in ["arch", "fedora"] else "sudo"
run_command(f"useradd -m -G {config['user_groups']} -s /bin/bash jonnybravo", "Benutzer 'jonnybravo' hinzufügen")
run_command("passwd jonnybravo", "Passwort für jonnybravo setzen", input_str=password_input)
# SSH-Schlüssel für jonnybravo einrichten
if args.ssh_key:
print("--- Richte SSH-Schlüssel für Benutzer 'jonnybravo' ein ---")
ssh_dir = "/home/jonnybravo/.ssh"
authorized_keys_file = os.path.join(ssh_dir, "authorized_keys")
run_command(f"mkdir -p {ssh_dir}", f"Erstelle Verzeichnis {ssh_dir}")
run_command(f"echo '{args.ssh_key}' > {authorized_keys_file}", f"Schreibe Schlüssel nach {authorized_keys_file}")
run_command(f"chown -R jonnybravo:jonnybravo {ssh_dir}", f"Setze Eigentümer für {ssh_dir}")
run_command(f"chmod 700 {ssh_dir}", f"Setze Berechtigungen für {ssh_dir}")
run_command(f"chmod 600 {authorized_keys_file}", f"Setze Berechtigungen für {authorized_keys_file}")
if wheel_group_equivalent == "wheel":
run_command("echo '%wheel ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/wheel_nopasswd", "Passwortloses sudo für Gruppe 'wheel' aktivieren")
else: # sudo group