Pular para o conteúdo

Linux SSH and sudo

This page covers the built-in Linux SSH template: SSH and sudo on a Linux server, authenticated by OkYouIn through pam_radius_auth. For RADIUS concepts see RADIUS.

PlatformSoftwareModesWhat was verified
Ubuntu26.04 (OpenSSH, pam_radius 3.0.0, sudo-rs 0.2.13)password, MFA only, password + MFASSH and sudo with TOTP in the keyboard-interactive / sudo prompt; Web Push with number matching; MFA only after the local password (the local password is not sent to OkYouIn); SSH session accounting Start / Stop
First factorOkYouIn checks the password, or MFA only — after the SSH key (variant A) or after the local Linux password (variant B).
Second factorTOTP, e-mail code, push (Web Push with number matching, Telegram) in the keyboard-interactive prompt.
ScopeOnly members of a local group okyouin; every other account keeps its local login.
AccountingSSH sessions: Start / Stop with session time. sudo has no session accounting.
Client IPSSH sends the client address. sudo sends none, so network conditions do not match for sudo.
  1. In OkYouIn, open Access ▸ Applications ▸ Add application and pick Linux SSH. Add the server’s address under Sources and choose the First factor. The Connect tab shows the files for the chosen mode with real values.

  2. Keep a root session open for the whole change, and test both a key login and an OkYouIn login in new sessions before closing it.

The examples use OkYouIn at 192.0.2.10 and the NAS-Identifier web-01.

  1. Install pam_radius (Debian / Ubuntu: package libpam-radius-auth).

  2. Add OkYouIn to /etc/pam_radius_auth.conf and make the file readable by root only (root:root, mode 600):

    # server[:port] shared_secret timeout (s)
    192.0.2.10:1812 <SHARED-SECRET> 60
  3. Create the group okyouin and add the accounts that log in through OkYouIn.

  4. Edit /etc/pam.d/sshd and /etc/pam.d/sudo and add the sshd drop-in /etc/ssh/sshd_config.d/10-okyouin.conf for your first-factor mode:

    /etc/pam.d/sshd and /etc/pam.d/sudo — replace @include common-auth with:

    auth [success=ignore default=1] pam_succeed_if.so quiet user ingroup okyouin
    auth [success=done new_authtok_reqd=done default=die] pam_radius_auth.so client_id=web-01
    @include common-auth

    /etc/ssh/sshd_config.d/10-okyouin.conf:

    Match Group okyouin
    KbdInteractiveAuthentication yes
    AuthenticationMethods keyboard-interactive

    In MFA-only mode, sudo uses the local password, then the code — /etc/pam.d/sudo:

    @include common-auth
    auth [success=ignore default=1] pam_succeed_if.so quiet user ingroup okyouin
    auth required pam_radius_auth.so force_prompt skip_passwd client_id=web-01
  5. Check with sshd -t, then systemctl reload ssh.

Rules that matter:

  • client_id= is required on every pam_radius_auth.so line. Without it pam_radius sends the PAM service name (sshd, sudo) as NAS-Identifier and OkYouIn does not accept the request.
  • MFA only: keep force_prompt skip_passwd. Without force_prompt, pam_radius reuses the password an earlier module already read and sends the local Linux password to the RADIUS server; skip_passwd alone does not stop that. With both, OkYouIn receives an empty password and asks only for the code.
  • The drop-in wins. sshd keeps the first value it reads, so a drop-in overrides the main sshd_config (Ubuntu’s sets KbdInteractiveAuthentication no after the include). Never set AuthenticationMethods outside the Match block: it would apply to every account, including your own admin and automation logins. UsePAM yes (the Debian / Ubuntu default) must stay on.

Add the two session lines after @include common-session in /etc/pam.d/sshd:

session [success=ignore default=1] pam_succeed_if.so quiet user ingroup okyouin
session optional pam_radius_auth.so client_id=web-01

pam_radius sends Accounting Start when the SSH session opens and Stop when it closes, with the session time; the sessions (user, client address, sshd PID as session ID) are on the application’s Sessions tab.

  • Keep the pam_succeed_if line: without it every account sends accounting.
  • Keep optional: with required, an unreachable OkYouIn refuses the SSH session after a successful login.
  • No Interim-Update, byte counters or disconnect cause: leave Interim interval (seconds) empty.

Reply attributes from application rules have no effect on Linux: pam_radius 3.0.0 uses only Management-Privilege-Level (with its privilege_level option) and Framed-IP-Address, as PAM variables.

pam_radius 3.0.0 sends Message-Authenticator in every Access-Request, so Strict is safe and recommended for this application. New applications start at Standard.

  1. From another machine, ssh in as a member of okyouin and complete the code prompt.

  2. Run sudo -v and complete it again.

  3. Check Logging ▸ RADIUS log and the application’s Sessions tab.

  4. Confirm that an account outside the okyouin group still logs in as before.

SymptomLikely cause
Login hangs for 60 seconds, then failsThe request is dropped — client_id= is missing on a pam_radius_auth.so line, the server’s address is not among the application’s Sources, or the secret is wrong. See Logging ▸ RADIUS log ▸ Dropped packets. The timeout in pam_radius_auth.conf is how long a dropped request blocks the login.
Reject nas_identifier_mismatchclient_id= differs from the application’s NAS-Identifier.
”Too many sign-in attempts, try again in N minutes”Every SSH login and every sudo is one challenge of the per-user challenge limit (Access ▸ Settings ▸ RADIUS).
A wrong password at sudo locks the account soonersudo retries three times; each wrong password counts toward the account lockout.