This article or section needs expansion.
SSH keys can serve as a means of identifying yourself to an SSH server usingpublic-key cryptography andchallenge-response authentication. The major advantage of key-based authentication is that, in contrast to password authentication, it is not prone tobrute-force attacks, and you do not expose valid credentials if the server has been compromised (seeRFC 4251 9.4.4).
Furthermore, SSH key authentication can be more convenient than the more traditional password authentication. When used with a program known as an SSH agent, SSH keys can allow you to connect to a server, or multiple servers, without having to remember or enter your password for each system.
Key-based authentication is not without its drawbacks and may not be appropriate for all environments, but in many circumstances it can offer some strong advantages. A general understanding of how SSH keys work will help you decide how and when to use them to meet your needs.
This article assumes you already have a basic understanding of theSecure Shell protocol and haveinstalled theopenssh package.
SSH keys are always generated in pairs with one known as the private key and the other as the public key. The private key is known only to you and it should be safely guarded. By contrast, the public key can be shared freely with any SSH server to which you wish to connect.
If an SSH server has your public key on file and sees you requesting a connection, it uses your public key to construct and send you a challenge. This challenge is an encrypted message and it must be met with the appropriate response before the server will grant you access. What makes this coded message particularly secure is that it can only be understood by the private key holder. While the public key can be used to encrypt the message, it cannot be used to decrypt that very same message. Only you, the holder of the private key, will be able to correctly understand the challenge and produce the proper response.
Thischallenge-response phase happens behind the scenes and is invisible to the user. As long as you hold the private key, which is typically stored in the~/.ssh/
directory, your SSH client should be able to reply with the appropriate response to the server.
A private key is a guarded secret and as such it is advisable to store it on disk in an encrypted form. When the encrypted private key is required, a passphrase must first be entered in order to decrypt it. While this might superficially appear as though you are providing a login password to the SSH server, the passphrase is only used to decrypt the private key on the local system. The passphrase is not transmitted over the network.
An SSH key pair can be generated by running thessh-keygen
command, see thessh-keygen(1) man page for what is "generally considered sufficient" and should be compatible with virtually all clients and servers:
$ ssh-keygen
Generating public/private ed25519 key pair.Enter file in which to save the key (/home/username/.ssh/id_ed25519):Created directory '/home/username/.ssh'.Enter passphrase (empty for no passphrase):Enter same passphrase again:Your identification has been saved in /home/username/.ssh/id_ed25519Your public key has been saved in /home/username/.ssh/id_ed25519.pubThe key fingerprint is:SHA256:RLy4JBv7jMK5qYhRKwHB3af0rpMKYwE2PBhALCBV3G8username@hostnameThe key's randomart image is:+--[ED25519 256]--+|%oooo. .. ||== ..o.o. ||== . +o.. ||+ o o.ooE ||... *.oS || o..o .. ||o=.. +o ||+o*..+o ||+.o+. . |+----[SHA256]-----+
Therandomart image wasintroduced in OpenSSH 5.1 as an easier means of visually identifying the key fingerprint.
-a
switch to specify the number of KDF rounds on the password encryption.You can also add an optional comment field to the public key with the-C
switch, to more easily identify it in places such as~/.ssh/known_hosts
,~/.ssh/authorized_keys
andssh-add -L
output. For example:
$ ssh-keygen -C "$(whoami)@$(uname -n)-$(date -I)"
will add a comment saying which user created the key on which machine and when.
OpenSSH supports several signing algorithms (for authentication keys) which can be divided in two groups depending on the mathematical properties they exploit:
Elliptic curve cryptography (ECC) algorithms are amore recent addition to public key cryptosystems. One of their main advantages is their ability to providethe same level of security with smaller keys, which makes for less computationally intensive operations (i.e. faster key creation, encryption and decryption) and reduced storage and transmission requirements.
DSA keys aredeprecated due to their security weaknesses and most SSH implementations do not support them anymore. Dropbear 2022.83 disabled DSA key support while OpenSSH 10.0 and libssh 0.11.0 removed support for DSA keys entirely. Therefore the choice ofcryptosystem lies within RSA or one of the two types of ECC.
The default Ed25519 will give you the best security and good performance. ECDSA is slower than Ed25519, but faster than RSA; concerns exist about its security (see below). RSA keys will give you the greatest compatibility with old servers, but it requires a larger key size to provide sufficient security.
Ed25519 was introduced inOpenSSH 6.5 of January 2014: "Ed25519 is an elliptic curve signature scheme that offers better security than ECDSA and DSA and good performance". Its main strengths are its speed, its constant-time run time (and resistance against side-channel attacks), and its lack of nebulous hard-coded constants.[1] See alsothis blog post by a Mozilla developer on how it works.
It is implemented inmany applications and libraries and is the default key type inssh-keygen(1) anddropbearkey(1).
ssh-keygen(1) defaults to Ed25519 therefore there is no need to specify it with the-t ed25519
option. The key pairs can be simply generated with:
$ ssh-keygen
There is no need to set the key size, as all Ed25519 keys are 256 bits.
Keep in mind that ancient SSH clients and servers may not support these keys.
The Elliptic Curve Digital Signature Algorithm (ECDSA) was the preferred algorithm for authentication (key exchange algorithm) fromOpenSSH 5.7 (2011-01-24) to OpenSSH 6.5 (2014-01-30).
There are two sorts of concerns with it:
Both of those concerns are best summarized inlibssh curve25519 introduction. Although the political concerns are still subject to debate, there is aclear consensus that#Ed25519 is technically superior and should therefore be preferred.
ECDSA key pairs can be generated with:
$ ssh-keygen -t ecdsa
Three elliptic curve sizes are supported for ECDSA keys: 256, 384 and 521 bits. The default is 256 bits. If you wish to generate a stronger ECDSA key pair, simply specify the-b
option:
$ ssh-keygen -t ecdsa -b 384
RSA provides the best compatibility of all algorithms but requires the key size to be larger to provide sufficient security. Minimum key size is 1024 bits, default is 3072 (seessh-keygen(1)) and maximum is 16384.
RSA key pairs can be generated with:
$ ssh-keygen -t rsa
If you wish to generate a stronger RSA key pair (e.g. to guard against cutting-edge or unknown attacks and more sophisticated attackers), simply specify the-b
option with a higher bit value than the default:
$ ssh-keygen -t rsa -b 4096
Be aware though that there are diminishing returns in using longer keys.[2][3] The GnuPG FAQ reads: "If you need more security than RSA-2048 offers, the way to go would be to switch to elliptical curve cryptography — not to continue using RSA."[4]
On the other hand, the latest iteration of theNSA Fact Sheet Suite B Cryptography suggests a minimum 3072-bit modulus for RSA while "[preparing] for the upcoming quantum resistant algorithm transition".[5]
FIDO/U2Fhardware authenticator support was added inOpenSSH version 8.2 for both of the elliptic curve signature schemes mentioned above. It allows for a hardware token attached via USB or other means to act a second factor alongside the private key.
Thelibfido2 is required for hardware token support.
ed25519-sk
andecdsa-sk
key types.SSH_SK_PROVIDER
environment variable forssh-keygen
andssh-add
.After attaching a compatible FIDO key, a key pair may be generated with:
$ ssh-keygen -t ed25519-sk
You will usually be required to enter your PIN and/or tap your token to confirm the generation. Connecting to a server will usually require tapping your token unless the-O no-touch-required
command line option is used during generation and thesshd(8) § no-touch-requiredauthorized_keys
option is set on the server.
To create keys that do not require touch events, generate a key pair with theno-touch-required
option. For example:
$ ssh-keygen -O no-touch-required -t ed25519-sk
Additionally,sshd
rejectsno-touch-required
keys by default. To allow keys generated with this option, either enable it for an individual key in theauthorized_keys
file:
~/.ssh/authorized_keys
no-touch-required sk-ssh-ed25519@openssh.com AAAAInN... user@example.com
Or for the whole system by editing/etc/ssh/sshd_config
with:
PubkeyAuthOptions none
An ECDSA-based keypair may also be generated with theecdsa-sk
keytype, but the relevant concerns in the#ECDSA section above still apply.
$ ssh-keygen -t ecdsa-sk
Upon issuing thessh-keygen
command, you will be prompted for the desired name and location of your private key. By default, keys are stored in the~/.ssh/
directory and named according to the type of encryption used. You are advised to accept the default name and location in order for later code examples in this article to work properly.
When prompted for a passphrase, choose something that will be hard to guess if you have the security of your private key in mind. A longer, more random password will generally be stronger and harder to crack should it fall into the wrong hands.
It is also possible to create your private key without a passphrase. While this can be convenient, you need to be aware of the associated risks. Without a passphrase, your private key will be stored on disk in an unencrypted form. Anyone who gains access to your private key file will then be able to assume your identity on any SSH server to which you connect using key-based authentication. Furthermore, without a passphrase, you must also trust the root user, as they can bypass file permissions and will be able to access your unencrypted private key file at any time.
If the originally chosen SSH key passphrase is undesirable or must be changed, one can use thessh-keygen
command to change the passphrase without changing the actual key. This can also be used to change the password encoding format to the new standard.
$ ssh-keygen -f ~/.ssh/id_rsa -p
If you have multiple SSH identities, you can set different keys to be used for different hosts or remote users by using theHost
andIdentityFile
directives in your configuration:
~/.ssh/config
Host SERVER1 IdentitiesOnly yes IdentityFile ~/.ssh/id_rsa_IDENTITY1Host SERVER2 SERVER3 IdentitiesOnly yes IdentityFile ~/.ssh/id_ed25519_IDENTITY2
Seessh_config(5) for full description of these options.
SSH keys can also be stored on a security token like a smart card or a USB token. This has the advantage that the private key is stored securely on the token instead of being stored on disk. When using a security token the sensitive private key is also never present in the RAM of the PC; the cryptographic operations are performed on the token itself. A cryptographic token has the additional advantage that it is not bound to a single computer; it can easily be removed from the computer and carried around to be used on other computers.
Examples of hardware tokens are described in:
This article or section needs expansion.
Once you have generated a key pair, you will need to copy the public key to the remote server so that it will use SSH key authentication. The public key file shares the same name as the private key except that it is appended with a.pub
extension. Note that the private key is not shared and remains on the local machine.
If your key file is~/.ssh/id_rsa.pub
you can simply enter the following command.
$ ssh-copy-id remote-server.org
If your username differs on remote machine, be sure to prepend the username followed by@
to the server name.
$ ssh-copy-id username@remote-server.org
If your public key filename is anything other than the default of~/.ssh/id_rsa.pub
you will get an error stating/usr/bin/ssh-copy-id: ERROR: No identities found
. In this case, you must explicitly provide the location of the public key.
$ ssh-copy-id -i ~/.ssh/id_ed25519.pub username@remote-server.org
If the ssh server is listening on a port other than default of 22, be sure to include it within the host argument.
$ ssh-copy-id -i ~/.ssh/id_ed25519.pub -p 221 username@remote-server.org
By default, for OpenSSH, the public key needs to be concatenated with~/.ssh/authorized_keys
. Begin by copying the public key to the remote server.
$ scp ~/.ssh/id_ecdsa.pub username@remote-server.org:
The above example copies the public key (id_ecdsa.pub
) to your home directory on the remote server viascp
. Do not forget to include the:
at the end of the server address. Also note that the name of your public key may differ from the example given.
On the remote server, you will need to create the~/.ssh
directory if it does not yet exist and append your public key to theauthorized_keys
file.
$ ssh username@remote-server.org
username@remote-server.org's password:
$ install -dm700 ~/.ssh$ cat ~/id_ecdsa.pub >> ~/.ssh/authorized_keys$ rm ~/id_ecdsa.pub$ chmod 600 ~/.ssh/authorized_keys
The last two commands remove the public key file from the server and set the permissions on theauthorized_keys
file such that it is only readable and writable by you, the owner.
If your private key is encrypted with a passphrase, this passphrase must be entered every time you attempt to connect to an SSH server using public-key authentication. Each individual invocation ofssh
orscp
will need the passphrase in order to decrypt your private key before authentication can proceed.
An SSH agent is a program which caches your decrypted private keys and provides them to SSH client programs on your behalf. In this arrangement, you must only provide your passphrase once, when adding your private key to the agent's cache. This facility can be of great convenience when making frequent SSH connections.
An agent is typically configured to run automatically upon login and persist for the duration of your login session. A variety of agents, front-ends, and configurations exist to achieve this effect. This section provides an overview of a number of different solutions which can be adapted to meet your specific needs.
ssh-agent
is the default agent included with OpenSSH. It can be used directly or serve as the back-end to a few of the front-end solutions mentioned later in this section. Whenssh-agent
is run, it forks to background and prints necessary environment variables. E.g.
$ ssh-agent
SSH_AUTH_SOCK=/tmp/ssh-vEGjCM2147/agent.2147; export SSH_AUTH_SOCK;SSH_AGENT_PID=2148; export SSH_AGENT_PID;echo Agent pid 2148;
To make use of these variables, run the command through theeval
command. Usessh-agent -c
instead if using thefish
shell.
$ eval $(ssh-agent)
Agent pid 2157
Oncessh-agent
is running, you will need to add your private key to its cache:
$ ssh-add ~/.ssh/id_ed25519
Enter passphrase for /home/user/.ssh/id_ed25519:Identity added: /home/user/.ssh/id_ed25519 (/home/user/.ssh/id_ed25519)
If your private key is encrypted,ssh-add
will prompt you to enter your passphrase. Once your private key has been successfully added to the agent you will be able to make SSH connections without having to enter your passphrase.
AddKeysToAgent yes
to~/.ssh/config
. Seessh_config(5) § AddKeysToAgent for other possible values.In order to start the agent automatically and make sure that only onessh-agent
process runs at a time,touch $XDG_RUNTIME_DIR/ssh-agent.env
and add the following to your~/.bashrc
:
if ! pgrep -u "$USER" ssh-agent > /dev/null; then ssh-agent -t 1h > "$XDG_RUNTIME_DIR/ssh-agent.env"fiif [ ! -f "$SSH_AUTH_SOCK" ]; then source "$XDG_RUNTIME_DIR/ssh-agent.env" >/dev/nullfi
This will run anssh-agent
process if there is not one already, and save the output thereof. If there is one running already, we retrieve the cachedssh-agent
output and evaluate it which will set the necessary environment variables. The lifetime of the unlocked keys is set to 1 hour.
There also exist a number of front-ends tossh-agent
and alternative agents described later in this section which avoid this problem.
If you would like your ssh agent to run when you are logged in, regardless of whether X is running, a handyssh-agent.service
is included inopenssh since the version 9.4p1-3, which can beenabled as auser unit.
Thenset the environment variableSSH_AUTH_SOCK
to$XDG_RUNTIME_DIR/ssh-agent.socket
.
This article or section needs language, wiki syntax or style improvements. SeeHelp:Style for reference.
Whenforwarding a localssh-agent
to remote (e.g., through command-line argumentssh -A remote
or throughForwardAgent yes
in the configuration file), it is important for the remote machine not to overwrite the environment variableSSH_AUTH_SOCK
. So if the remote machine uses asystemd unit shown previously to start the agent,SSH_AUTH_SOCK
must not be set in the environment when a user is logged in through SSH. Otherwise, the forwarding may fail, and you may see errors (for example:The agent has no identities
) when checking the existing keys withssh-add -l
on the remote machine.
For example, if using bash, the.bashrc
could be something like:
~/.bashrc
...if [[ -z "${SSH_CONNECTION}" ]]; then export SSH_AUTH_SOCK="$XDG_RUNTIME_DIR/ssh-agent.socket"fi...
In this way,SSH_AUTH_SOCK
is only set when the current session isnot an SSH login. And when this is a SSH session,SSH_AUTH_SOCK
on the remote machine is then set by the local machine to make the forwarding work.
An alternative way to start ssh-agent (with, say, each X session) is described inthis ssh-agent tutorial by UC Berkeley Labs. A basic use case is if you normally begin X with thestartx
command, you can instead prefix it withssh-agent
like so:
$ ssh-agent startx
And so you do not even need to think about it you can put an alias in your.bash_aliases
file or equivalent:
alias startx='ssh-agent startx'
Doing it this way avoids the problem of having extraneousssh-agent
instances floating around between login sessions. Exactly one instance will live and die with the entire X session.
ssh-askpass
requires theDISPLAY
orWAYLAND_DISPLAY
environment variable to work, so you may want to runssh-agent
in~/.xinitrc
instead ofssh-agent startx
, whereDISPLAY
is set. For example, you can addexec ssh-agent dbus-launch i3
to~/.xinitrc
. Or as an alternative to usingssh-agent
as a wrapper program, you can addeval $(ssh-agent)
to~/.xinitrc
.Seethe notes on using x11-ssh-askpass with ssh-add for an idea on how to immediately add your key to the agent.
This ssh-agent specializes onOpenPGP card integration. It uses private keys that are stored inOpenPGP card authentication slots.
Installopenpgp-card-ssh-agent andenable andstart theopenpgp-card-ssh-agent.socket
user unit.
Afterwards add the relevantenvironment variable for this agent:
SSH_AUTH_SOCK="$XDG_RUNTIME_DIR/openpgp-card/ssh-agent.sock"
The user PIN for theOpenPGP card is persisted via anorg.freedesktop.secrets provider (such asGNOME Keyring,KeePassXC orKDE Wallet) by default. The PIN storage backend isconfigurable and extendable.
The user PIN needs to be persisted only once for eachOpenPGP card. Prior to the first SSH connection with this agent, list the available SSH public keys and add their respective card identifiers:
$ ssh-add -L
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJUz6VnFprMe33G88Pq8NLw3wnIKOsBg0CDrwFeUVrU6FFFE:01234567
$ ssh-add -sFFFE:01234567
Enter passphrase for PKCS#11:
Thegpg-agent has OpenSSH Agent protocol emulation. SeeGnuPG#SSH agent for necessary configuration.
Keychain is a program designed to help you easily manage your SSH keys with minimal user interaction. It is implemented as a shell script which drives bothssh-agent andssh-add. A notable feature of Keychain is that it can maintain a singlessh-agent process across multiple login sessions. This means that you only need to enter your passphrase once each time your local machine is booted.
-Q, --quick
option has the unexpected side-effect of makingkeychain switch to a newly-spawnedssh-agent upon relogin (at least on systems usingGNOME), forcing you to re-add all the previously registered keys.Add a line similar to the following to yourshell configuration file,e.g. if usingBash:
~/.bashrc
eval $(keychain --eval --quiet id_ed25519 id_rsa ~/.keys/my_custom_key)
~/.bashrc
is used instead of the upstream suggested~/.bash_profile
because on Arch it is sourced by both login and non-login shells, making it suitable for textual and graphical environments alike. SeeBash#Invocation for more information on the difference between those.In the above example,
--eval
switch outputs lines to be evaluated by the openingeval
command; this sets the necessary environment variables for an SSH client to be able to find your agent.--quiet
will limit output to warnings, errors, and user prompts.Multiple keys can be specified on the command line, as shown in the example. By default keychain will look for key pairs in the~/.ssh/
directory, but absolute path can be used for keys in non-standard location. You may also use the--confhost
option to inform keychain to look in~/.ssh/config
forIdentityFile
settings defined for particular hosts, and use these paths to locate keys.
Seekeychain --help
orkeychain(1) for details on settingkeychain for other shells.
To test Keychain, simply open a new terminal emulator or log out and back in your session. It should prompt you for the passphrase of the specified private key(s) (if applicable), either using the program set in$SSH_ASKPASS
or on the terminal.
Because Keychain reuses the samessh-agent process on successive logins, you should not have to enter your passphrase the next time you log in or open a new terminal. You will only be prompted for your passphrase once each time the machine is rebooted.
.pub
extension. If the private key is a symlink, the public key can be found alongside the symlink or in the same directory as the symlink target (this capability requires thereadlink
command to be available on the system).--nogui
option. This allows to copy-paste long passphrases from a password manager for example.--noask
option.--agents
option,e.g.--agents ssh,gpg
. Seekeychain(1).--agents
option is deprecated. Seekeychain(1).--inherit any-once
as perkeychain issue 148.Thex11-ssh-askpass package provides a graphical dialog for entering your passhrase when running an X session.x11-ssh-askpass depends only on thelibx11 andlibxt libraries, and the appearance ofx11-ssh-askpass is customizable. While it can be invoked by thessh-add program, which will then load your decrypted keys intossh-agent, the following instructions will, instead, configurex11-ssh-askpass to be invoked by the aforementionedKeychain script.
Install thekeychain andx11-ssh-askpass packages.
Edit your~/.xinitrc
file to include the following lines, replacing the name and location of your private key if necessary. Be sure to place these commandsbefore the line which invokes your window manager.
~/.xinitrc
keychain ~/.ssh/id_ecdsa[ -f ~/.keychain/$HOSTNAME-sh ] && . ~/.keychain/$HOSTNAME-sh 2>/dev/null[ -f ~/.keychain/$HOSTNAME-sh-gpg ] && . ~/.keychain/$HOSTNAME-sh-gpg 2>/dev/null...exec openbox-session
In the above example, the first line invokeskeychain and passes the name and location of your private key. If this is not the first timekeychain was invoked, the following two lines load the contents of$HOSTNAME-sh
and$HOSTNAME-sh-gpg
, if they exist. These files store the environment variables of the previous instance ofkeychain.
Thessh-add manual page specifies that, in addition to needing theDISPLAY
orWAYLAND_DISPLAY
variable defined, you also needSSH_ASKPASS
set to the name of your askpass program (in this casex11-ssh-askpass). It bears keeping in mind that the default Arch Linux installation places thex11-ssh-askpass binary in/usr/lib/ssh/
, which will not be in most people'sPATH
. This is a little annoying, not only when declaring theSSH_ASKPASS
variable, but also when theming. You have to specify the full path everywhere. Both inconveniences can be solved simultaneously by symlinking:
$ ln -sv /usr/lib/ssh/x11-ssh-askpass ~/bin/ssh-askpass
This is assuming that~/bin
is in yourPATH
. So now in your.xinitrc
, before calling your window manager, one just needs to export theSSH_ASKPASS
environment variable:
$ export SSH_ASKPASS=ssh-askpass
and yourX resources will contain something like:
ssh-askpass*background: #000000
Doing it this way works well withthe above method on usingssh-agent as a wrapper program. You start X withssh-agent startx
and then addssh-add to your window manager's list of start-up programs.
The appearance of thex11-ssh-askpass dialog can be customized by setting its associatedX resources. Some examples are the .ad files athttps://github.com/sigmavirus24/x11-ssh-askpass. Seex11-ssh-askpass(1) for full details.
There are other passphrase dialog programs which can be used instead ofx11-ssh-askpass. The following list provides some alternative solutions.
/usr/lib/seahorse/ssh-askpass
) uses theGTK library.Thepam_ssh project exists to provide aPluggable Authentication Module (PAM) for SSH private keys. This module can provide single sign-on behavior for your SSH connections. On login, your SSH private key passphrase can be entered in place of, or in addition to, your traditional system password. Once you have been authenticated, the pam_ssh module spawns ssh-agent to store your decrypted private key for the duration of the session.
To enable single sign-on behavior at the tty login prompt, install the unofficialpam_sshAUR package.
~/.ssh/login-keys.d/
.Create a symlink to your private key file and place it in~/.ssh/login-keys.d/
. Replace theid_rsa
in the example below with the name of your own private key file.
$ mkdir ~/.ssh/login-keys.d/$ cd ~/.ssh/login-keys.d/$ ln -s ../id_rsa
Edit the/etc/pam.d/login
configuration file to include the text highlighted in bold in the example below. The order in which these lines appear is significiant and can affect login behavior.
/etc/pam.d/login
#%PAM-1.0auth required pam_securetty.soauth requisite pam_nologin.soauth include system-local-loginauth optional pam_ssh.so try_first_passaccount include system-local-loginsession include system-local-loginsession optional pam_ssh.so
In the above example, login authentication initially proceeds as it normally would, with the user being prompted to enter their user password. The additionalauth
authentication rule added to the end of the authentication stack then instructs the pam_ssh module to try to decrypt any private keys found in the~/.ssh/login-keys.d
directory. Thetry_first_pass
option is passed to the pam_ssh module, instructing it to first try to decrypt any SSH private keys using the previously entered user password. If the user's private key passphrase and user password are the same, this should succeed and the user will not be prompted to enter the same password twice. In the case where the user's private key passphrase user password differ, the pam_ssh module will prompt the user to enter the SSH passphrase after the user password has been entered. Theoptional
control value ensures that users without an SSH private key are still able to log in. In this way, the use of pam_ssh will be transparent to users without an SSH private key.
If you use another means of logging in, such as an X11 display manager likeSLiM orXDM and you would like it to provide similar functionality, you must edit its associated PAM configuration file in a similar fashion. Packages providing support for PAM typically place a default configuration file in the/etc/pam.d/
directory.
Further details on how to use pam_ssh and a list of its options can be found in thepam_ssh(8) man page.
If you want to unlock the SSH keys or not depending on whether you use your key's passphrase or the (different!) login password, you can modify/etc/pam.d/system-auth
to
/etc/pam.d/system-auth
#%PAM-1.0auth [success=1 new_authtok_reqd=1 ignore=ignore default=ignore] pam_unix.so try_first_pass nullokauth required pam_ssh.so use_first_passauth optional pam_permit.soauth required pam_env.soaccount required pam_unix.soaccount optional pam_permit.soaccount required pam_time.sopassword required pam_unix.so try_first_pass nullok sha512 shadowpassword optional pam_permit.sosession required pam_limits.sosession required pam_unix.sosession optional pam_permit.sosession optional pam_ssh.so
For an explanation, see[7].
Work on the pam_ssh project is infrequent and the documentation provided is sparse. You should be aware of some of its limitations which are not mentioned in the package itself.
ssh-agent
process spawned by pam_ssh does not persist between user logins. If you like to keep aGNU Screen session active between logins you may notice when reattaching to your screen session that it can no longer communicate with ssh-agent. This is because the GNU Screen environment and those of its children will still reference the instance of ssh-agent which existed when GNU Screen was invoked but was subsequently killed in a previous logout. TheKeychain front-end avoids this problem by keeping the ssh-agent process alive between logins.As an alternative topam_ssh you can usepam_exec-ssh-gitAUR. It is a shell script that uses pam_exec. Help for configuration can be foundupstream.
TheGNOME Keyring tool can act as a wrapper around ssh-agent, providing GUI and/or automatic key unlocking. SeeGNOME Keyring#SSH keys for further details.
For instructions on how to use kwallet to store your SSH keys, seeKDE Wallet#Using the KDE Wallet to store ssh key passphrases.
KeeAgent is a plugin forKeePass that allows SSH keys stored in a KeePass database to be used for SSH authentication by other programs.
SeeKeePass#Plugin installation in KeePass orinstall thekeepass-plugin-keeagent package.
This agent can be used directly, by matching KeeAgent socket:KeePass -> Tools -> Options -> KeeAgent -> Agent mode socket file -> %XDG_RUNTIME_DIR%/keeagent.socket
and environment variable:export SSH_AUTH_SOCK="$XDG_RUNTIME_DIR"'/keeagent.socket'
.
The KeePassXC fork of KeePasscan act as a client for an existing SSH agent. SSH keys stored in its database can be automatically (or manually) added to the agent. It is also compatible with KeeAgent's database format.
$ chmod 700 ~/.ssh$ chmod 600 ~/.ssh/key
$ chmod 700 ~/.ssh$ chmod 600 ~/.ssh/authorized_keys
$ chmod go-w ~target_user
StrictModes
tono
in/etc/ssh/sshd_config
. If authentication withStrictModes off
is successful, it is likely an issue with file permissions persists.~/.ssh/authorized_keys
are entered correctly and only use one single line.# /usr/bin/sshd -d
id_rsa_server
, you need to connect with the-i
option:$ ssh -i id_rsa_server user@server
If your private key requires a password (or, for instance, you have a hardware key with a PIN) but ssh-agent is not provided with one,ssh
will fail:
sign_and_send_pubkey: signing failed for ECDSA-SKuser@host from agent: agent refused operation
One potential cause for this is ssh-agent being unable to prompt for a password. Ensure that ssh-agent has access to either a display server (via theDISPLAY
environment variable) or a TTY. For some graphical environments you might only need toinstallx11-ssh-askpass, for other setups also follow#x11-ssh-askpass instructions.
Another cause, if using a hardware authenticator, could be the key malfunctioning or being unplugged.
There is currently an openbug that triggers with the "agent refused operation" error when using authenticator keys like ED25519-sk and ECDSA-SK that were created with the option-O verify-required
. To avoid this issue, use the-o IdentityAgent=none -o IdentitiesOnly=yes
option for thessh
command or add it to yourssh_config
file for the relevant hosts:
Host myserver.tld IdentityAgent none IdentitiesOnly yes