prevents_entering_a_waiting_state_during_an_ssh_session_connection

외부에서 SSH로 접속중에 원격지의 시스템이 대기 상태에 돌입하면 당황스럽다.

이런경우 다음의 두가지로 확실하게 방지해보자.

1. Polkit 규칙 파일

/etc/polkit-1/rules.d/10-ssh-keepgoing.rules

polkit.addRule(function(action, subject) {
    if (action.id == "org.freedesktop.login1.inhibit-block-idle" ||
        action.id == "org.freedesktop.login1.inhibit-block-sleep") {
        if (subject.isInGroup("<YOUR GROUP>") || subject.user == "<YOUR USER ID>") {
            return polkit.Result.YES;
        }
    }
});

2. Bash startup script

~/.bash_login 또는 ~/.bash_profile, ~/.profile 중 하나에서 다음 내용을 불러 올 수 있도록 작성.

# SSH 접속이고, 이미 inhibit 하위 세션이 아닐 때만 실행
if [ -n "$SSH_CONNECTION" ] && [ -z "$SYSTEMD_INHIBIT_ACTIVE" ]; then
    export SYSTEMD_INHIBIT_ACTIVE=1
    exec systemd-inhibit --what=idle:sleep \
                         --who="SSH-Session-$USER" \
                         --why="Active remote session" \
                         /usr/bin/bash --login
fi

적용 결과

다음과 같이 systemd-inhibit 아래에 쉘이 실행됩니다.

  • prevents_entering_a_waiting_state_during_an_ssh_session_connection.txt
  • 마지막으로 수정됨: 2026/04/04 17:52
  • 저자 baecy