recipes/src/machine_admin/ssh_config.py
2024-09-29 14:06:05 +01:00

32 lines
873 B
Python

from pathlib import Path
import logging
from .util import run_op
logger = logging.getLogger(__name__)
class SshConfig:
def __init__(self):
self.config_path = Path("/etc/ssh/ssh_config")
self.target_values = {
"PermitRootLogin": "No",
"PasswordAuthentication": "No",
"ChallengeResponseAuthentication": "No",
"UsePAM": "No",
}
def sync_target_values(self):
logger.info(f"Updating ssh config in: {self.config_path}")
pass
def restart_service(self):
op = "systemctl restart ssh"
logger.info(f"Restarting ssh service: {op}")
run_op(op)
def copy_ssh_dir_to_user(self, username: str):
op = f"rsync --archive --chown={username}:{username} ~/.ssh /home/{username}"
logger.info(f"Copying ssh dir to user: {op}")
run_op(op)