Format of the authorized_keys file

The AuthorizedKeysFile keyword specifies the file containing public keys for public key authentication. If none is specified, the default is ~/.ssh/authorized_keys and ~/.ssh.authorized_keys2.

Each line of the file contains one key specification (empty lines and lines starting with # are ignored as comments).
  • Protocol version 1 public keys consist of the following space-separated fields: options, bits, exponent, modulus, comment. The bits, exponent, modulus, and comment fields give the RSA key for protocol version 1.
  • Protocol version 2 public keys that are not in key rings consist of options, keytype, base64-encoded key, comment. The options field is optional; its presence is determined by whether the line starts with a number (the options field never starts with a number).

    Protocol version 2 public keys that are in a key ring only consist of options, one of which must be the zos-key-ring-label option.

    For protocol version 2, the keytype is "ssh-dss", "ssh-rsa", “ecdsa-sha2-nistp256”, “ecdsa-sha2- nistp384”, or “ecdsa-sha2-nistp521”.

Lines in this file are typically several hundred bytes long (because of the size of the public key encoding) up to a limit of 8 kilobytes, which permits DSA keys up to 8 kilobits and RSA keys up to 16 kilobits. To avoid typing them, copy the,,, or file and edit it.

sshd enforces a minimum RSA key modulus size for protocol version 1 and protocol version 2 keys of 768 bits.

The options field (if present) consists of comma-separated option specifications. No spaces are permitted, except within double quotes. The following option specifications are supported (note that option keywords are not case sensitive):
Specifies that the listed key is a certification authority (CA) that is trusted to validate signed certificates for user authentication.

Certificates may encode access restrictions similar to these key options. If both certificate restrictions and key options are present, the most restrictive union of the two is applied.

Specifies that the command is executed whenever this key is used for authentication. The command supplied by the user (if any) is ignored. The command is on a pseudo terminal (pty) if the client requests a pty; otherwise it is run without a tty. If an 8-bit clean channel is required, do not request a pty or should specify no-pty. A quote can be included in the command by quoting it with a backslash. This option can be useful to restrict certain public keys to perform just a specific operation. An example might be a key that permits remote backups but nothing else. The client can specify any combination of TCP and X11 forwarding unless they are explicitly prohibited. The command originally supplied by the client is available in the SSH_ORIGINAL_COMMAND environment variable. This option applies to shell, command, or subsystem execution.
Note: This command may be superseded by either a sshd_config(5) ForceCommand directive or a command embedded in a certificate.
Specifies that the string is to be added to the environment when logging in using this key. Environment variables set this way override other default environment values. See Environment variables in ssh for more information. Multiple options of this type are permitted. Environment processing is disabled by default and is controlled by means of the PermitUserEnvironment option. This option is automatically disabled if UseLogin is enabled.

See PermitUserEnvironment for information about environment variable processing and precedence rules. The sshd_config keyword UseLogin is documented in UseLogin.

Specifies that in addition to public key authentication, the canonical name of the remote host must be present in the comma-separated list of patterns. The purpose of this option is to increase security; public key authentication by itself does not trust the network or name servers or anything but the key. However, if the key is stolen, this additional option makes using a stolen key more difficult because name servers and routers would have to be compromised in addition to just the key.

The purpose of this option is to optionally increase security: public key authentication by itself does not trust the network or name servers or anything (but the key); however, if somebody somehow steals the key, the key permits an intruder to log in from anywhere in the world. This additional option makes using a stolen key more difficult (name servers and/or routers would have to be compromised in addition to just the key).

See Patterns for more information about patterns.

Prevents authentication agent forwarding when this key is used for authentication.
Prevents TCP forwarding when this key is used for authentication. Any port forward requests by the client will return an error. This option can be used in conjunction with the command option.
Prevents tty allocation (a request to allocate a pty will fail).
Disables execution of the ~/.ssh/rc file.
Prevents X11 forwarding when this key is used for authentication. Any X11 forward requests by the client will return an error.
Limits local ssh –L port forwarding such that it can only connect to the specified host and port. IPv6 addresses can be specified with an alternate syntax: host/port. Use commas to separate multiple permitopen options. No pattern matching is performed on the specified host names, they must be literal domains or addresses. A port specification of “*” matches any port.

OpenSSH - port forwarding examples has examples of port forwarding.

On a cert-authority line, specifies allowed principals for certificate authentication as a comma separated list. At least one name from the list must appear in the certificate's list of principals for the certificate to be accepted. This option is ignored for keys that are not marked as trusted certificate signers using the cert-authority option.
This option is ignored on z/OS UNIX. Forces a tunnel device on the server. Without this option, the next available device is used if the client requests a tunnel.
zos-key-ring-label="KeyRingOwner/KeyRingName label"
Specifies the key ring owner, key ring name, and the certificate label within the key ring on the OpenSSH server that contains the user's public key. One or more blanks separate the key ring (real or virtual) name from the certificate label. Certificate labels can contain embedded blanks. The option value must be enclosed in double quotes. Key fields following the options (on the same line) are ignored.
Requirements: These requirements must be met.
  • The certificate must be copied from the client system and added to the user's key ring on the OpenSSH server.
  • If the user is not storing the authorized keys in a key ring, then the public key must be extracted from the certificate and added to the user's authorized keys on the OpenSSH server.

If a key ring is being used on the server side (for example, SSHAuthKeysRing), it was created in the user authentication setup described in Steps for setting up user authentication when using key rings to store keys.

An example of an authorized_keys file:
# Comments allowed at start of line
ssh-rsa AAAAB3Nza...LiPk== 
from="*,!" ssh-rsa AAAAB2...19Q==
command="dump /home",no-pty,no-port-forwarding ssh-dss AAAAC3...51R==
permitopen="",permitopen="" ssh-dss AAAAB5...21S==
zos-key-ring-label="KeyRingOwner/SSHAuthKeysRing uniq-ssh-rsa"
from="*",zos-key-ring-label="KeyRingOwner/SSHAuthKeysRing uniq-ssh-dsa"