pam_ssh_agent_auth(8)
π pam_ssh_agent_auth(8) β the PAM module that lets your SSH agent say βsheβs with meβ β¨
okay bestie, welcome to the manual page for pam_ssh_agent_auth(8) π«Ά yes, thatβs the manual name, and no, weβre not skipping the technical bits. Letβs get into it.
πΈ NAME πΈ
pam_ssh_agent_auth β a PAM module for granting permissions based on SSH agent requests. Itβs giving βthe agent already vouched for me, so let me in.β π
β¨ DESCRIPTION β¨
okay so this module provides authentication via ssh keys. If an ssh-agent listening at SSH_AUTH_SOCK can successfully authenticate that it has the secret key for a public key in the specified file, authentication is granted. If the public key originally used to authenticate at sshd matches an authorized key, authentication succeeds. Otherwise authentication fails. Thatβs the whole plot, no cap. π
π οΈ CONFIGURATION π οΈ
Two big setups here: sudo and sshd. Both are lowkey iconic.
π SUDO π
Pop this into /etc/pam.d/sudo:
auth sufficient pam_ssh_agent_auth.so file=/etc/security/authorized_keys
Then in /etc/sudoers, you gotta enable sudo to pass the environment variable pointing to the ssh authentication socket:
Defaults env_keep += "SSH_AUTH_SOCK"
This configuration would permit anyone who has an SSH_AUTH_SOCK that manages the private key matching a public key in /etc/security/authorized_keys to execute sudo without having to enter a password. Note that the ssh-agent listening to SSH_AUTH_SOCK can either be local, or forwarded. Both are valid, bestie. π«Ά
Unlike NOPASSWD, this still requires an authentication, itβs just that the authentication is provided by ssh-agent, and not password entry. So itβs not βno auth,β itβs βauth by agent.β Important distinction, periodt. π
π¦ SSHD π¦
Your /etc/ssh/sshd_config wants:
PubkeyAuthentication yes
AuthenticationMethods publickey,keyboard-interactive:pam
PasswordAuthentication no
UsePAM yes
and your /etc/pam.d/sshd wants:
auth required pam_permit.so
auth sufficient pam_ssh_agent_auth.so file=/etc/security/super_authorized_keys
auth sufficient pam_secondary_auth_method.so
...
auth requisite pam_deny.so
This configuration would permit anyone who originally authenticated to sshd with a public key also found in /etc/security/super_authorized_keys to log in without having to complete other PAM auth methods. Anyone whose ssh key was accepted initially by sshd but whose key is not in the allowlist must complete another secondary PAM module such as OTP or else be denied. So close, but the allowlist is the vibe check. β¨
βοΈ ARGUMENTS βοΈ
These are the flags and knobs, and every single one gets its moment:
file=<path to authorized_keys>β Specify the path to theauthorized_keysfile(s) you would like to use for authentication. Subject to tilde and%EXPANSIONS (below). ποΈallow_user_owned_authorized_keys_fileβ A flag which enablesauthorized_keysfiles to be owned by the invoking user, instead of root. This flag is enabled automatically whenever the expansions%hor~are used. πauthorized_keys_command=<path to executable>β Specify an external command to run, which should take a single argument, the username of the person being authenticated, and emit to its stdout a file inauthorized_keysformat. This is ideally suited for use with sssdβssss_ssh_authorizedkeys, for authenticating users viaauthorized_keysstored in ldap or other sssd supported security service. π§authorized_keys_command_user=<username>β Specify a user to run theauthorized_keys_commandas. If this option is not specified, theauthorized_keys_commandwill be run as the user being authenticated. π€debugβ A flag which enables verbose logging. For when you need the receipts. π§Ύsudo_service_name=<service name you compiled sudo to use>β (when compiled with--enable-sudo-hack)
Specify the service name to use to identify the service "sudo". When the PAM_SERVICE identifier matches this string, and if PAM_RUSER is not set, pam_ssh_agent_auth will attempt to identify the calling user from the environment variable SUDO_USER.
This defaults to "sudo". π
π§ EXPANSIONS π§
These little symbols expand into paths and host info, iykyk:
~β same as in shells, a userβs Home directory. Automatically enablesallow_user_owned_authorized_keys_fileif used in the context of~/.. If used as~user/, it would expect the file to be owned by βuserβ, unless you explicitly setallow_user_owned_authorized_keys_file. π%hβ Userβs Home directory. Automatically enablesallow_user_owned_authorized_keys_file. π‘%Hβ The short-hostname. π₯οΈ%uβ Username. πͺͺ%fβ FQDN. π
π EXAMPLES π
Examples time, bestie. These all live in /etc/pam.d/sudo.
Example 1 β the default user key:
"auth sufficient pam_ssh_agent_auth.so file=~/.ssh/authorized_keys"
The default .ssh/authorized_keys file in a userβs home-directory.
Example 2 β same as above:
"auth sufficient pam_ssh_agent_auth.so file=%h/.ssh/authorized_keys"
Same as above.
Example 3 β ~fred energy:
"auth sufficient pam_ssh_agent_auth.so file=~fred/.ssh/authorized_keys"
If the home-directory of user βfredβ was /home/fred, this would expand to /home/fred/.ssh/authorized_keys. In this case, we have not specified allow_user_owned_authorized_keys_file, so this file must be owned by βfredβ.
Example 4 β %H and %u with the ownership flag:
"auth sufficient pam_ssh_agent_auth.so
file=/secure/%H/%u/authorized_keys
allow_user_owned_authorized_keys_file"
On a host named foobar.baz.com, and a user named fred, would expand to /secure/foobar/fred/authorized_keys. In this case, we specified allow_user_owned_authorized_keys_file, so fred would be able to manage that authorized_keys file himself.
Example 5 β %f FQDN:
"auth sufficient pam_ssh_agent_auth.so
file=/secure/%f/%u/authorized_keys"
On a host named foobar.baz.com, and a user named fred, would expand to /secure/foobar.baz.com/fred/authorized_keys. In this case, we have not specified allow_user_owned_authorized_keys_file, so this file must be owned by root.
Example 6 β control flow with success=3:
"auth [success=3 default=ignore] pam_ssh_agent_auth.so
file=~/.ssh/authorized_keys debug"
This pam.d config format allows for more control over how pam handles success and failure. In this example, we use success=3, which specifies that when this module succeeds, pam should jump over the next 3 auth modules and continue from there. This is useful, for instance, if /etc/pam.d/common-auth is included, and contains 3 "auth required" or similar module rules that we wish to skip, but we wish not to skip other auth rules.
For more information, please see http://linux.die.net/man/5/pam.d.
π COPYRIGHT π
okay legal bestie moment β hereβs the copyright and license text, kept exactly as it needs to be. Do not @ me, Iβm not editing legal text π
Copyright (c) 2008-2014, Jamie Beverly. And is based on openssh, and the included works by Markus Friedl, Darren Tucker, Todd C. Miller, Ben Lindstrom, Tim Rice, Damien Miller, Liz Fong-Jones, and many others. All rights reserved. See sources for complete attributions. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY Jamie Beverly ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Jamie Beverly OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
okay thatβs literally the whole manual, bestie π«Ά β this page is from pam_ssh_agent_auth v0.10.3, dated 2022-01-11, and thatβs the footer energy, slay π
β¨
π¦ where this page comes from
- opensuse-leap 16.0: pam_ssh_agent_auth 0.10.4-bp160.1.12 Β· OpenSSL
- opensuse-leap 16.0: pam_ssh_agent_auth 0.10.4-bp160.1.12 Β· OpenSSL
- opensuse-leap 16.0: pam_ssh_agent_auth 0.10.4-bp160.1.12 Β· OpenSSL
- opensuse-leap 16.0: pam_ssh_agent_auth 0.10.4-bp160.1.12 Β· OpenSSL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms