{
    "content": [
        {
            "type": "text",
            "text": "# KEYCTL (man)\n\n## NAME\n\nkeyctl - key management facility control\n\n## SYNOPSIS\n\nkeyctl --version\nkeyctl supports [<cap> | --raw]\nkeyctl id [<keyring>]\nkeyctl show [-x] [<keyring>]\nkeyctl add [-x] <type> <desc> <data> <keyring>\nkeyctl padd [-x] <type> <desc> <keyring>\nkeyctl request <type> <desc> [<destkeyring>]\nkeyctl request2 <type> <desc> <info> [<destkeyring>]\nkeyctl prequest2 <type> <desc> [<destkeyring>]\nkeyctl update [-x] <key> <data>\nkeyctl pupdate [-x] <key>\nkeyctl newring <name> <keyring>\nkeyctl revoke <key>\nkeyctl clear <keyring>\nkeyctl link <key> <keyring>\nkeyctl unlink <key> [<keyring>]\nkeyctl move [-f] <key> <fromkeyring> <tokeyring>\nkeyctl search <keyring> <type> <desc> [<destkeyring>]\nkeyctl restrictkeyring <keyring> [<type> [<restriction>]]\nkeyctl read <key>\nkeyctl pipe <key>\nkeyctl print <key>\nkeyctl list <keyring>\nkeyctl rlist <keyring>\nkeyctl describe <keyring>\nkeyctl rdescribe <keyring> [sep]\nkeyctl chown <key> <uid>\nkeyctl chgrp <key> <gid>\nkeyctl setperm <key> <mask>\nkeyctl newsession [<name>]\nkeyctl session\nkeyctl session - [<prog> <arg1> <arg2> ...]\nkeyctl session <name> [<prog> <arg1> <arg2> ...]\nkeyctl instantiate [-x] <key> <data> <keyring>\nkeyctl pinstantiate [-x] <key> <keyring>\nkeyctl negate <key> <timeout> <keyring>\nkeyctl reject <key> <timeout> <error> <keyring>\nkeyctl timeout <key> <timeout>\nkeyctl security <key>\nkeyctl reap [-v]\nkeyctl purge <type>\nkeyctl purge [-i] [-p] <type> <desc>\nkeyctl purge -s <type> <desc>\nkeyctl getpersistent <keyring> [<uid>]\nkeyctl dhcompute <private> <prime> <base>\nkeyctl dhcomputekdf <private> <prime> <base> <outputlength> <hashtype>\nkeyctl dhcomputekdfoi [-x] <private> <prime> <base> <outputlength> <hashtype>\nkeyctl pkeyquery <key> <pass> [k=v]*\nkeyctl pkeyencrypt <key> <pass> <datafile> [k=v]* ><encfile>\nkeyctl pkeydecrypt <key> <pass> <encfile> [k=v]* ><datafile>\nkeyctl pkeysign <key> <pass> <datafile> [k=v]* ><sigfile>\nkeyctl pkeydecrypt <key> <pass> <datafile> <sigfile> [k=v]*\nkeyctl watch [-f<filters>] <key>\nkeyctl watchadd <fd> <key>\nkeyctl watchrm <fd> <key>\nkeyctl watchsession [-f <filters>] [-n <name>] \\\n<notifylog> <gclog> <fd> <prog> [<arg1> <arg2> ...]\n\n## DESCRIPTION\n\nThis  program  is used to control the key management facility in various ways using a variety\nof subcommands.\n\n## TLDR\n\n> Manipulate the Linux kernel keyring.\n\n- List keys in a specific keyring:\n  `keyctl list {{target_keyring}}`\n- List current keys in the user default session:\n  `keyctl list {{@us}}`\n- Store a key in a specific keyring:\n  `keyctl add {{type_keyring}} {{key_name}} {{key_value}} {{target_keyring}}`\n- Store a key with its value from `stdin`:\n  `echo -n {{key_value}} | keyctl padd {{type_keyring}} {{key_name}} {{target_keyring}}`\n- Put a timeout on a key:\n  `keyctl timeout {{key_name}} {{timeout_in_seconds}}`\n- Read a key and format it as a hex-dump if not printable:\n  `keyctl read {{key_name}}`\n- Read a key and format as-is:\n  `keyctl pipe {{key_name}}`\n- Revoke a key and prevent any further action on it:\n  `keyctl revoke {{key_name}}`\n\n*Source: tldr-pages*\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **KEY IDENTIFIERS**\n- **COMMAND SYNTAX** (49 subsections)\n- **ERRORS**\n- **SEE ALSO**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "KEYCTL",
        "section": "",
        "mode": "man",
        "summary": "keyctl - key management facility control",
        "synopsis": "keyctl --version\nkeyctl supports [<cap> | --raw]\nkeyctl id [<keyring>]\nkeyctl show [-x] [<keyring>]\nkeyctl add [-x] <type> <desc> <data> <keyring>\nkeyctl padd [-x] <type> <desc> <keyring>\nkeyctl request <type> <desc> [<destkeyring>]\nkeyctl request2 <type> <desc> <info> [<destkeyring>]\nkeyctl prequest2 <type> <desc> [<destkeyring>]\nkeyctl update [-x] <key> <data>\nkeyctl pupdate [-x] <key>\nkeyctl newring <name> <keyring>\nkeyctl revoke <key>\nkeyctl clear <keyring>\nkeyctl link <key> <keyring>\nkeyctl unlink <key> [<keyring>]\nkeyctl move [-f] <key> <fromkeyring> <tokeyring>\nkeyctl search <keyring> <type> <desc> [<destkeyring>]\nkeyctl restrictkeyring <keyring> [<type> [<restriction>]]\nkeyctl read <key>\nkeyctl pipe <key>\nkeyctl print <key>\nkeyctl list <keyring>\nkeyctl rlist <keyring>\nkeyctl describe <keyring>\nkeyctl rdescribe <keyring> [sep]\nkeyctl chown <key> <uid>\nkeyctl chgrp <key> <gid>\nkeyctl setperm <key> <mask>\nkeyctl newsession [<name>]\nkeyctl session\nkeyctl session - [<prog> <arg1> <arg2> ...]\nkeyctl session <name> [<prog> <arg1> <arg2> ...]\nkeyctl instantiate [-x] <key> <data> <keyring>\nkeyctl pinstantiate [-x] <key> <keyring>\nkeyctl negate <key> <timeout> <keyring>\nkeyctl reject <key> <timeout> <error> <keyring>\nkeyctl timeout <key> <timeout>\nkeyctl security <key>\nkeyctl reap [-v]\nkeyctl purge <type>\nkeyctl purge [-i] [-p] <type> <desc>\nkeyctl purge -s <type> <desc>\nkeyctl getpersistent <keyring> [<uid>]\nkeyctl dhcompute <private> <prime> <base>\nkeyctl dhcomputekdf <private> <prime> <base> <outputlength> <hashtype>\nkeyctl dhcomputekdfoi [-x] <private> <prime> <base> <outputlength> <hashtype>\nkeyctl pkeyquery <key> <pass> [k=v]*\nkeyctl pkeyencrypt <key> <pass> <datafile> [k=v]* ><encfile>\nkeyctl pkeydecrypt <key> <pass> <encfile> [k=v]* ><datafile>\nkeyctl pkeysign <key> <pass> <datafile> [k=v]* ><sigfile>\nkeyctl pkeydecrypt <key> <pass> <datafile> <sigfile> [k=v]*\nkeyctl watch [-f<filters>] <key>\nkeyctl watchadd <fd> <key>\nkeyctl watchrm <fd> <key>\nkeyctl watchsession [-f <filters>] [-n <name>] \\\n<notifylog> <gclog> <fd> <prog> [<arg1> <arg2> ...]",
        "tldr_summary": "Manipulate the Linux kernel keyring.",
        "tldr_examples": [
            {
                "description": "List keys in a specific keyring",
                "command": "keyctl list {{target_keyring}}"
            },
            {
                "description": "List current keys in the user default session",
                "command": "keyctl list {{@us}}"
            },
            {
                "description": "Store a key in a specific keyring",
                "command": "keyctl add {{type_keyring}} {{key_name}} {{key_value}} {{target_keyring}}"
            },
            {
                "description": "Store a key with its value from `stdin`",
                "command": "echo -n {{key_value}} | keyctl padd {{type_keyring}} {{key_name}} {{target_keyring}}"
            },
            {
                "description": "Put a timeout on a key",
                "command": "keyctl timeout {{key_name}} {{timeout_in_seconds}}"
            },
            {
                "description": "Read a key and format it as a hex-dump if not printable",
                "command": "keyctl read {{key_name}}"
            },
            {
                "description": "Read a key and format as-is",
                "command": "keyctl pipe {{key_name}}"
            },
            {
                "description": "Revoke a key and prevent any further action on it",
                "command": "keyctl revoke {{key_name}}"
            }
        ],
        "tldr_source": "official",
        "flags": [],
        "examples": [],
        "see_also": [
            {
                "name": "keyctl",
                "section": "1",
                "url": "https://www.chedong.com/phpMan.php/man/keyctl/1/json"
            },
            {
                "name": "keyctl",
                "section": "2",
                "url": "https://www.chedong.com/phpMan.php/man/keyctl/2/json"
            },
            {
                "name": "requestkey",
                "section": "2",
                "url": "https://www.chedong.com/phpMan.php/man/requestkey/2/json"
            },
            {
                "name": "keyctl",
                "section": "3",
                "url": "https://www.chedong.com/phpMan.php/man/keyctl/3/json"
            },
            {
                "name": "request-key.conf",
                "section": "5",
                "url": "https://www.chedong.com/phpMan.php/man/request-key.conf/5/json"
            },
            {
                "name": "keyrings",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/keyrings/7/json"
            },
            {
                "name": "request-key",
                "section": "8",
                "url": "https://www.chedong.com/phpMan.php/man/request-key/8/json"
            }
        ],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 58,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "KEY IDENTIFIERS",
                "lines": 44,
                "subsections": []
            },
            {
                "name": "COMMAND SYNTAX",
                "lines": 4,
                "subsections": [
                    {
                        "name": "Display the package version number",
                        "lines": 1
                    },
                    {
                        "name": "keyctl --version",
                        "lines": 5
                    },
                    {
                        "name": "Query subsystem capabilities",
                        "lines": 26
                    },
                    {
                        "name": "capabilities",
                        "lines": 3
                    },
                    {
                        "name": "persistent_keyrings",
                        "lines": 2
                    },
                    {
                        "name": "dh_compute",
                        "lines": 2
                    },
                    {
                        "name": "public_key",
                        "lines": 2
                    },
                    {
                        "name": "big_key_type",
                        "lines": 2
                    },
                    {
                        "name": "key_invalidate",
                        "lines": 2
                    },
                    {
                        "name": "restrict_keyring",
                        "lines": 2
                    },
                    {
                        "name": "move_key",
                        "lines": 2
                    },
                    {
                        "name": "ns_keyring_name",
                        "lines": 3
                    },
                    {
                        "name": "ns_key_tag",
                        "lines": 5
                    },
                    {
                        "name": "Show actual key or keyring ID",
                        "lines": 1
                    },
                    {
                        "name": "keyctl id [<key>]",
                        "lines": 6
                    },
                    {
                        "name": "Show process keyrings",
                        "lines": 1
                    },
                    {
                        "name": "keyctl show [-x] [<keyring>]",
                        "lines": 4
                    },
                    {
                        "name": "Add a key to a keyring",
                        "lines": 18
                    },
                    {
                        "name": "Request a key",
                        "lines": 30
                    },
                    {
                        "name": "Update a key",
                        "lines": 17
                    },
                    {
                        "name": "Create a keyring",
                        "lines": 8
                    },
                    {
                        "name": "Revoke a key",
                        "lines": 9
                    },
                    {
                        "name": "Clear a keyring",
                        "lines": 7
                    },
                    {
                        "name": "Link a key to a keyring",
                        "lines": 13
                    },
                    {
                        "name": "Unlink a key from a keyring or the session keyring tree",
                        "lines": 13
                    },
                    {
                        "name": "Move a key between keyrings.",
                        "lines": 12
                    },
                    {
                        "name": "Search a keyring",
                        "lines": 12
                    },
                    {
                        "name": "Restrict a keyring",
                        "lines": 10
                    },
                    {
                        "name": "Read a key",
                        "lines": 19
                    },
                    {
                        "name": "List a keyring",
                        "lines": 15
                    },
                    {
                        "name": "Describe a key",
                        "lines": 16
                    },
                    {
                        "name": "Change the access controls on a key",
                        "lines": 16
                    },
                    {
                        "name": "Set the permissions mask on a key",
                        "lines": 32
                    },
                    {
                        "name": "Start a new session with fresh keyrings",
                        "lines": 1
                    },
                    {
                        "name": "keyctl session",
                        "lines": 43
                    },
                    {
                        "name": "Instantiate a key",
                        "lines": 36
                    },
                    {
                        "name": "Set the expiry time on a key",
                        "lines": 7
                    },
                    {
                        "name": "Retrieve a key's security context",
                        "lines": 8
                    },
                    {
                        "name": "Give the parent process a new session keyring",
                        "lines": 1
                    },
                    {
                        "name": "keyctl new_session [<name>]",
                        "lines": 21
                    },
                    {
                        "name": "Remove dead keys from the session keyring tree",
                        "lines": 1
                    },
                    {
                        "name": "keyctl reap",
                        "lines": 13
                    },
                    {
                        "name": "Remove matching keys from the session keyring tree",
                        "lines": 22
                    },
                    {
                        "name": "Get persistent keyring",
                        "lines": 16
                    },
                    {
                        "name": "Compute a Diffie-Hellman shared secret or public key",
                        "lines": 18
                    },
                    {
                        "name": "Compute a Diffie-Hellman shared secret and derive key material",
                        "lines": 13
                    },
                    {
                        "name": "Compute a Diffie-Hellman shared secret and apply KDF with other input",
                        "lines": 9
                    },
                    {
                        "name": "Perform public-key operations with an asymmetric key",
                        "lines": 35
                    },
                    {
                        "name": "Change notifications",
                        "lines": 51
                    }
                ]
            },
            {
                "name": "ERRORS",
                "lines": 12,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 4,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "keyctl - key management facility control\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "keyctl --version\nkeyctl supports [<cap> | --raw]\nkeyctl id [<keyring>]\nkeyctl show [-x] [<keyring>]\nkeyctl add [-x] <type> <desc> <data> <keyring>\nkeyctl padd [-x] <type> <desc> <keyring>\nkeyctl request <type> <desc> [<destkeyring>]\nkeyctl request2 <type> <desc> <info> [<destkeyring>]\nkeyctl prequest2 <type> <desc> [<destkeyring>]\nkeyctl update [-x] <key> <data>\nkeyctl pupdate [-x] <key>\nkeyctl newring <name> <keyring>\nkeyctl revoke <key>\nkeyctl clear <keyring>\nkeyctl link <key> <keyring>\nkeyctl unlink <key> [<keyring>]\nkeyctl move [-f] <key> <fromkeyring> <tokeyring>\nkeyctl search <keyring> <type> <desc> [<destkeyring>]\nkeyctl restrictkeyring <keyring> [<type> [<restriction>]]\nkeyctl read <key>\nkeyctl pipe <key>\nkeyctl print <key>\nkeyctl list <keyring>\nkeyctl rlist <keyring>\nkeyctl describe <keyring>\nkeyctl rdescribe <keyring> [sep]\nkeyctl chown <key> <uid>\nkeyctl chgrp <key> <gid>\nkeyctl setperm <key> <mask>\nkeyctl newsession [<name>]\nkeyctl session\nkeyctl session - [<prog> <arg1> <arg2> ...]\nkeyctl session <name> [<prog> <arg1> <arg2> ...]\nkeyctl instantiate [-x] <key> <data> <keyring>\nkeyctl pinstantiate [-x] <key> <keyring>\nkeyctl negate <key> <timeout> <keyring>\nkeyctl reject <key> <timeout> <error> <keyring>\nkeyctl timeout <key> <timeout>\nkeyctl security <key>\nkeyctl reap [-v]\nkeyctl purge <type>\nkeyctl purge [-i] [-p] <type> <desc>\nkeyctl purge -s <type> <desc>\nkeyctl getpersistent <keyring> [<uid>]\nkeyctl dhcompute <private> <prime> <base>\nkeyctl dhcomputekdf <private> <prime> <base> <outputlength> <hashtype>\nkeyctl dhcomputekdfoi [-x] <private> <prime> <base> <outputlength> <hashtype>\nkeyctl pkeyquery <key> <pass> [k=v]*\nkeyctl pkeyencrypt <key> <pass> <datafile> [k=v]* ><encfile>\nkeyctl pkeydecrypt <key> <pass> <encfile> [k=v]* ><datafile>\nkeyctl pkeysign <key> <pass> <datafile> [k=v]* ><sigfile>\nkeyctl pkeydecrypt <key> <pass> <datafile> <sigfile> [k=v]*\nkeyctl watch [-f<filters>] <key>\nkeyctl watchadd <fd> <key>\nkeyctl watchrm <fd> <key>\nkeyctl watchsession [-f <filters>] [-n <name>] \\\n<notifylog> <gclog> <fd> <prog> [<arg1> <arg2> ...]\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "This  program  is used to control the key management facility in various ways using a variety\nof subcommands.\n",
                "subsections": []
            },
            "KEY IDENTIFIERS": {
                "content": "The key identifiers passed to or returned from keyctl are,  in  general,  positive  integers.\nThere  are,  however,  some  special values with special meanings that can be passed as argu‐\nments:\n\nNo key: 0\n\nThread keyring: @t or -1\nEach thread may have its own keyring. This is searched first, before all  others.  The\nthread keyring is replaced by (v)fork, exec and clone.\n\nProcess keyring: @p or -2\nEach  process (thread group) may have its own keyring. This is shared between all mem‐\nbers of a group and will be searched after the thread keyring. The process keyring  is\nreplaced by (v)fork and exec.\n\nSession keyring: @s or -3\nEach  process  subscribes  to a session keyring that is inherited across (v)fork, exec\nand clone. This is searched after the process keyring. Session keyrings can  be  named\nand an extant keyring can be joined in place of a process's current session keyring.\n\nUser specific keyring: @u or -4\nThis  keyring is shared between all the processes owned by a particular user. It isn't\nsearched directly, but is normally linked to from the session keyring.\n\nUser default session keyring: @us or -5\nThis is the default session keyring for a particular user. Login processes that change\nto a particular user will bind to this session until another session is set.\n\nGroup specific keyring: @g or -6\nThis is a place holder for a group specific keyring, but is not  actually  implemented\nyet in the kernel.\n\nAssumed requestkey authorisation key: @a or -7\nThis  selects  the authorisation key provided to the requestkey() helper to permit it\nto access the callers keyrings and instantiate the target key.\n\nKeyring by name: %:<name>\nA named keyring.  This  will  be  searched  for  in  the  process's  keyrings  and  in\n/proc/keys.\n\nKey by name: %<type>:<name>\nA  named  key  of the given type.  This will be searched for in the process's keyrings\nand in /proc/keys.\n",
                "subsections": []
            },
            "COMMAND SYNTAX": {
                "content": "Any non-ambiguous shortening of a command name may be used in lieu of the full command  name.\nThis  facility  should  not  be used in scripting as new commands may be added in future that\nthen cause ambiguity.\n",
                "subsections": [
                    {
                        "name": "Display the package version number",
                        "content": ""
                    },
                    {
                        "name": "keyctl --version",
                        "content": "This command prints the package version number and build date and exits:\n\n$ keyctl --version\nkeyctl from keyutils-1.5.3 (Built 2011-08-24)\n"
                    },
                    {
                        "name": "Query subsystem capabilities",
                        "content": "keyctl supports\nkeyctl supports --raw\nkeyctl supports <cap>\n\nThis command can list the available capabilities:\n\n$ keyctl supports\nhavecapabilities=0\nhavepersistentkeyrings=1\nhavedhcompute=1\nhavepublickey=1\n\nproduce a raw hex dump of the capabilities list:\n\n$ keyctl supports --raw\nff0f\n\nor query a specific capability:\n\n$ keyctl supports pkey\necho $?\n0\n\nwhich exits 0 if the capability is supported, 1 if it isn't and 3 if the name is  not  recog‐\nnised.  The capabilities supported are:\n"
                    },
                    {
                        "name": "capabilities",
                        "content": "The  kernel  supports  capability  querying.   If  not, the other capabilities will be\nqueried as best libkeyutils can manage.\n"
                    },
                    {
                        "name": "persistent_keyrings",
                        "content": "The kernel supports persistent keyrings.\n"
                    },
                    {
                        "name": "dh_compute",
                        "content": "The kernel supports Diffie-Hellman computation operations.\n"
                    },
                    {
                        "name": "public_key",
                        "content": "The kernel supports public key operations.\n"
                    },
                    {
                        "name": "big_key_type",
                        "content": "The kernel supports the bigkey key type.\n"
                    },
                    {
                        "name": "key_invalidate",
                        "content": "The kernel supports the invalidate key operaiton.\n"
                    },
                    {
                        "name": "restrict_keyring",
                        "content": "The kernel supports the restrictkeyring operation.\n"
                    },
                    {
                        "name": "move_key",
                        "content": "The kernel supports the move key operation.\n"
                    },
                    {
                        "name": "ns_keyring_name",
                        "content": "Keyring names are segregated according to the user-namespace in which the keyrings are\ncreated.\n"
                    },
                    {
                        "name": "ns_key_tag",
                        "content": "Keys can get tagged with namespace tags, allowing keys with the same type and descrip‐\ntion, but different namespaces to coexist in the same keyring.  Tagging is done  auto‐\nmatically according to the key type.\n\n"
                    },
                    {
                        "name": "Show actual key or keyring ID",
                        "content": ""
                    },
                    {
                        "name": "keyctl id [<key>]",
                        "content": "This  command  looks  up  the real ID of a key or keyring from the identifier given, which is\ntypically a symbolic ID such as \"@s\" indicating the session keyring, but can also  be  a  nu‐\nmeric ID or \"%type:desc\" notation.  If a special keyring is specified that isn't created yet,\nan error will be given rather than causing that keyring to be created.\n\n"
                    },
                    {
                        "name": "Show process keyrings",
                        "content": ""
                    },
                    {
                        "name": "keyctl show [-x] [<keyring>]",
                        "content": "By  default  this command recursively shows what keyrings a process is subscribed to and what\nkeys and keyrings they contain.  If a keyring is specified then that keyring will  be  dumped\ninstead.  If -x is specified then the keyring IDs will be dumped in hex instead of decimal.\n"
                    },
                    {
                        "name": "Add a key to a keyring",
                        "content": "keyctl add [-x] <type> <desc> <data> <keyring>\nkeyctl padd [-x] <type> <desc> <keyring>\n\nThis  command  creates  a key of the specified type and description; instantiates it with the\ngiven data and attaches it to the specified keyring. It then prints the new key's ID on  std‐\nout:\n\n$ keyctl add user mykey stuff @u\n26\n\nThe padd variant of the command reads the data from stdin rather than taking it from the com‐\nmand line:\n\n$ echo -n stuff | keyctl padd user mykey @u 26\n\nIf -x is given, then the data is hex-decoded with whitespace being discarded.\n\n"
                    },
                    {
                        "name": "Request a key",
                        "content": "keyctl request <type> <desc> [<destkeyring>]\nkeyctl request2 <type> <desc> <info> [<destkeyring>]\nkeyctl prequest2 <type> <desc> [<destkeyring>]\n\nThese  three  commands  request  the  lookup  of a key of the given type and description. The\nprocess's keyrings will be searched, and if a match is found the matching key's  ID  will  be\nprinted  to  stdout;  and  if  a  destination keyring is given, the key will be added to that\nkeyring also.\n\nIf there is no key, the first command will simply return the error ENOKEY and fail. The  sec‐\nond  and third commands will create a partial key with the type and description, and call out\nto /sbin/request-key with that key and the extra information supplied. This will then attempt\nto instantiate the key in some manner, such that a valid key is obtained.\n\nThe third command is like the second, except that the callout information is read from  stdin\nrather than being passed on the command line.\n\nIf  a  valid  key is obtained, the ID will be printed and the key attached as if the original\nsearch had succeeded.\n\nIf there wasn't a valid key obtained, a temporary negative key will be attached to the desti‐\nnation keyring if given and the error \"Requested key not available\" will be given.\n\n$ keyctl request2 user debug:hello wibble\n23\n$ echo -n wibble | keyctl prequest2 user debug:hello\n23\n$ keyctl request user debug:hello\n23\n"
                    },
                    {
                        "name": "Update a key",
                        "content": "keyctl update [-x] <key> <data>\nkeyctl pupdate [-x] <key>\n\nThis command replaces the data attached to a key with a new set of data. If the type  of  the\nkey doesn't support update then error \"Operation not supported\" will be returned.\n\n$ keyctl update 23 zebra\n\nThe  pupdate  variant of the command reads the data from stdin rather than taking it from the\ncommand line:\n\n$ echo -n zebra | keyctl pupdate 23\n$ echo 616263313233 | keyctl pupdate -x 23\n\nIf -x is given, then the data is hex-decoded with whitespace being discarded.\n\n"
                    },
                    {
                        "name": "Create a keyring",
                        "content": "keyctl newring <name> <keyring>\n\nThis command creates a new keyring of the specified name and attaches  it  to  the  specified\nkeyring. The ID of the new keyring will be printed to stdout if successful.\n\n$ keyctl newring squelch @us\n27\n"
                    },
                    {
                        "name": "Revoke a key",
                        "content": "keyctl revoke <key>\n\nThis command marks a key as being revoked. Any further operations on that key (apart from un‐\nlinking it) will return error \"Key has been revoked\".\n\n$ keyctl revoke 26\n$ keyctl describe 26\nkeyctldescribe: Key has been revoked\n"
                    },
                    {
                        "name": "Clear a keyring",
                        "content": "keyctl clear <keyring>\n\nThis  command unlinks all the keys attached to the specified keyring. Error \"Not a directory\"\nwill be returned if the key specified is not a keyring.\n\n$ keyctl clear 27\n"
                    },
                    {
                        "name": "Link a key to a keyring",
                        "content": "keyctl link <key> <keyring>\n\nThis command makes a link from the key to the keyring if there's enough capacity  to  do  so.\nError  \"Not a directory\" will be returned if the destination is not a keyring. Error \"Permis‐\nsion denied\" will be returned if the key doesn't have link permission or the keyring  doesn't\nhave  write  permission. Error \"File table overflow\" will be returned if the keyring is full.\nError \"Resource deadlock avoided\" will be returned if an attempt was made to introduce a  re‐\ncursive link.\n\n$ keyctl link 23 27\n$ keyctl link 27 27\nkeyctllink: Resource deadlock avoided\n"
                    },
                    {
                        "name": "Unlink a key from a keyring or the session keyring tree",
                        "content": "keyctl unlink <key> [<keyring>]\n\nIf  the  keyring is specified, this command removes a link to the key from the keyring. Error\n\"Not a directory\" will be returned if the destination is not a keyring. Error \"Permission de‐\nnied\" will be returned if the keyring doesn't have write permission. Error \"No such  file  or\ndirectory\" will be returned if the key is not linked to by the keyring.\n\nIf  the  keyring  is not specified, this command performs a depth-first search of the session\nkeyring tree and removes all the links to the nominated key that it finds  (and  that  it  is\npermitted to remove).  It prints the number of successful unlinks before exiting.\n\n$ keyctl unlink 23 27\n"
                    },
                    {
                        "name": "Move a key between keyrings.",
                        "content": "keyctl move  [-f] <key> <fromkeyring> <tokeyring>\n\nThis  command  moves  a  key from one keyring to another, atomically combining \"keyctl unlink\n<key> <fromkeyring>\" and \"keyctl link <key> <tokeyring>\".\n\nIf the \"-f\" flag is present, any matching key will be displaced  from  \"tokeyring\";  if  not\npresent,  the  command will fail with the error message \"File exists\" if the key would other‐\nwise displace another key from \"tokeyring\".\n\n$ keyctl move 23 27 29\n$ keyctl move -f 71 @u @s\n"
                    },
                    {
                        "name": "Search a keyring",
                        "content": "keyctl search <keyring> <type> <desc> [<destkeyring>]\n\nThis command non-recursively searches a keyring for a key of a particular type  and  descrip‐\ntion.  If  found, the ID of the key will be printed on stdout and the key will be attached to\nthe destination keyring if present. Error \"Requested key not available\" will be  returned  if\nthe key is not found.\n\n$ keyctl search @us user debug:hello\n23\n$ keyctl search @us user debug:bye\nkeyctlsearch: Requested key not available\n"
                    },
                    {
                        "name": "Restrict a keyring",
                        "content": "keyctl restrictkeyring <keyring> [<type> [<restriction>]]\n\nThis  command  limits  the  linkage of keys to the given keyring using a provided restriction\nscheme. The scheme is associated with a given key type, with further details provided in  the\nrestriction option string.  Options typically contain a restriction name possibly followed by\nkey  ids or other data relevant to the restriction. If no restriction scheme is provided, the\nkeyring will reject all links.\n\n$ keyctl restrictkeyring $1 asymmetric builtintrusted\n"
                    },
                    {
                        "name": "Read a key",
                        "content": "keyctl read <key>\nkeyctl pipe <key>\nkeyctl print <key>\n\nThese commands read the payload of a key. \"read\" prints it on stdout as a  hex  dump,  \"pipe\"\ndumps  the raw data to stdout and \"print\" dumps it to stdout directly if it's entirely print‐\nable or as a hexdump preceded by \":hex:\" if not.\n\nIf the key type does not support reading of the payload, then error \"Operation not supported\"\nwill be returned.\n\n$ keyctl read 26\n1 bytes of data in key:\n62\n$ keyctl print 26\nb\n$ keyctl pipe 26\n$\n"
                    },
                    {
                        "name": "List a keyring",
                        "content": "keyctl list <keyring>\nkeyctl rlist <keyring>\n\nThese commands list the contents of a key as a keyring. \"list\" pretty prints the contents and\n\"rlist\" just produces a space-separated list of key IDs.\n\nNo attempt is made to check that the specified keyring is a keyring.\n\n$ keyctl list @us\n2 keys in keyring:\n22: vrwsl----------  4043    -1 keyring: uid.4043\n23: vrwsl----------  4043  4043 user: debug:hello\n$ keyctl rlist @us\n22 23\n"
                    },
                    {
                        "name": "Describe a key",
                        "content": "keyctl describe <keyring>\nkeyctl rdescribe <keyring> [sep]\n\nThese commands fetch a description of a keyring. \"describe\" pretty prints the description  in\nthe  same  fashion  as  the \"list\" command; \"rdescribe\" prints the raw data returned from the\nkernel.\n\n$ keyctl describe @us\n-5: vrwsl----------  4043    -1 keyring: uidses.4043\n$ keyctl rdescribe @us\nkeyring;4043;-1;3f1f0000;uidses.4043\n\nThe raw string is \"<type>;<uid>;<gid>;<perms>;<description>\", where uid and gid are the deci‐\nmal user and group IDs, perms is the permissions mask in hex, type and  description  are  the\ntype name and description strings (neither of which will contain semicolons).\n"
                    },
                    {
                        "name": "Change the access controls on a key",
                        "content": "keyctl chown <key> <uid>\nkeyctl chgrp <key> <gid>\n\nThese  two  commands  change  the  UID and GID associated with evaluating a key's permissions\nmask. The UID also governs which quota a key is taken out of.\n\nThe chown command is not currently supported; attempting it will earn  the  error  \"Operation\nnot supported\" at best.\n\nFor  non-superuser  users,  the  GID  may  only  be  set to the process's GID or a GID in the\nprocess's groups list. The superuser may set any GID it likes.\n\n$ sudo keyctl chown 27 0\nkeyctlchown: Operation not supported\n$ sudo keyctl chgrp 27 0\n"
                    },
                    {
                        "name": "Set the permissions mask on a key",
                        "content": "keyctl setperm <key> <mask>\n\nThis command changes the permission control mask on a key. The mask may be specified as a hex\nnumber if it begins \"0x\", an octal number if it begins \"0\" or a decimal number otherwise.\n\nThe hex numbers are a combination of:\n\nPossessor UID       GID       Other     Permission Granted\n========  ========  ========  ========  ==================\n01000000  00010000  00000100  00000001  View\n02000000  00020000  00000200  00000002  Read\n04000000  00040000  00000400  00000004  Write\n08000000  00080000  00000800  00000008  Search\n10000000  00100000  00001000  00000010  Link\n20000000  00200000  00002000  00000020  Set Attribute\n3f000000  003f0000  00003f00  0000003f  All\n\nView permits the type, description and other parameters of a key to be viewed.\n\nRead permits the payload (or keyring list) to be read if supported by the type.\n\nWrite permits the payload (or keyring list) to be modified or updated.\n\nSearch on a key permits it to be found when a keyring to which it is linked is searched.\n\nLink permits a key to be linked to a keyring.\n\nSet Attribute permits a key to have its owner, group membership, permissions mask and timeout\nchanged.\n\n$ keyctl setperm 27 0x1f1f1f00\n"
                    },
                    {
                        "name": "Start a new session with fresh keyrings",
                        "content": ""
                    },
                    {
                        "name": "keyctl session",
                        "content": "keyctl session - [<prog> <arg1> <arg2> ...]\nkeyctl session <name> [<prog> <arg1> <arg2> ...]\n\nThese commands join or create a new keyring and then run a shell or other program  with  that\nkeyring as the session key.\n\nThe  variation  with no arguments just creates an anonymous session keyring and attaches that\nas the session keyring; it then exec's $SHELL.\n\nThe variation with a dash in place of a name creates an anonymous  session  keyring  and  at‐\ntaches  that  as  the  session keyring; it then exec's the supplied command, or $SHELL if one\nisn't supplied.\n\nThe variation with a name supplied creates or joins the named keyring and  attaches  that  as\nthe session keyring; it then exec's the supplied command, or $SHELL if one isn't supplied.\n\n$ keyctl rdescribe @s\nkeyring;4043;-1;3f1f0000;uidses.4043\n\n$ keyctl session\nJoined session keyring: 28\n\n$ keyctl rdescribe @s\nkeyring;4043;4043;3f1f0000;ses.24082\n\n$ keyctl session -\nJoined session keyring: 29\n$ keyctl rdescribe @s\nkeyring;4043;4043;3f1f0000;ses.24139\n\n$ keyctl session - keyctl rdescribe @s\nJoined session keyring: 30\nkeyring;4043;4043;3f1f0000;ses.24185\n\n$ keyctl session fish\nJoined session keyring: 34\n$ keyctl rdescribe @s\nkeyring;4043;4043;3f1f0000;fish\n\n$ keyctl session fish keyctl rdesc @s\nJoined session keyring: 35\nkeyring;4043;4043;3f1f0000;fish\n"
                    },
                    {
                        "name": "Instantiate a key",
                        "content": "keyctl instantiate [-x] <key> <data> <keyring>\nkeyctl pinstantiate [-x] <key> <keyring>\nkeyctl negate <key> <timeout> <keyring>\nkeyctl reject <key> <timeout> <error> <keyring>\n\nThese  commands  are  used to attach data to a partially set up key (as created by the kernel\nand passed to /sbin/request-key).  \"instantiate\" marks a key as being valid and attaches  the\ndata as the payload.  \"negate\" and \"reject\" mark a key as invalid and sets a timeout on it so\nthat  it'll  go  away after a while.  This prevents a lot of quickly sequential requests from\nslowing the system down overmuch when they all fail, as all  subsequent  requests  will  then\nfail  with  error \"Requested key not found\" (if negated) or the specified error (if rejected)\nuntil the negative key has expired.\n\nReject's error argument can either be a UNIX error number or one of 'rejected', 'expired'  or\n'revoked'.\n\nThe newly instantiated key will be attached to the specified keyring.\n\nThese  commands may only be run from the program run by request-key - a special authorisation\nkey is set up by the kernel and attached to the request-key's session keyring.  This  special\nkey is revoked once the key to which it refers has been instantiated one way or another.\n\n$ keyctl instantiate $1 \"Debug $3\" $4\n$ keyctl negate $1 30 $4\n$ keyctl reject $1 30 64 $4\n\nThe  pinstantiate variant of the command reads the data from stdin rather than taking it from\nthe command line:\n\n$ echo -n \"Debug $3\" | keyctl pinstantiate $1 $4\n\nIf -x is given, then the data is hex-decoded with whitespace being discarded:\n\n$ echo 01 02 03 04 | keyctl pinstantiate -x $1 $4\n\n"
                    },
                    {
                        "name": "Set the expiry time on a key",
                        "content": "keyctl timeout <key> <timeout>\n\nThis command is used to set the timeout on a key, or clear an existing timeout if  the  value\nspecified is zero. The timeout is given as a number of seconds into the future.\n\n$ keyctl timeout $1 45\n"
                    },
                    {
                        "name": "Retrieve a key's security context",
                        "content": "keyctl security <key>\n\nThis  command is used to retrieve a key's LSM security context.  The label is printed on std‐\nout.\n\n$ keyctl security @s\nunconfinedu:unconfinedr:unconfinedt:s0-s0:c0.c1023\n"
                    },
                    {
                        "name": "Give the parent process a new session keyring",
                        "content": ""
                    },
                    {
                        "name": "keyctl new_session [<name>]",
                        "content": "This command is used to give the invoking process (typically a shell) a new session  keyring,\ndiscarding its old session keyring.  If a name is given, the keyring is given that name, oth‐\nerwise it will be given a name of \"ses\" and will not be manually joinable.\n\n$  keyctl session foo\nJoined session keyring: 723488146\n$  keyctl show\nSession Keyring\n-3 --alswrv      0     0  keyring: foo\n$  keyctl newsession\n490511412\n$  keyctl show\nSession Keyring\n-3 --alswrv      0     0  keyring: ses\n\nNote  that  this  affects  the parent of the process that invokes the system call, and so may\nonly affect processes with matching credentials.  Furthermore, the change does not  take  ef‐\nfect  till  the  parent  process next transitions from kernel space to user space - typically\nwhen the wait() system call returns.\n\n"
                    },
                    {
                        "name": "Remove dead keys from the session keyring tree",
                        "content": ""
                    },
                    {
                        "name": "keyctl reap",
                        "content": "This command performs a depth-first search of the caller's session keyring tree and  attempts\nto  unlink any key that it finds that is inaccessible due to expiry, revocation, rejection or\nnegation.  It does not attempt to remove live keys that are unavailable simply due to a  lack\nof granted permission.\n\nA key that is designated reapable will only be removed from a keyring if the caller has Write\npermission on that keyring, and only keyrings that grant Search permission to the caller will\nbe searched.\n\nThe  command prints the number of keys reaped before it exits.  If the -v flag is passed then\nthe reaped keys are listed as they're being reaped, together with the success or  failure  of\nthe unlink.\n"
                    },
                    {
                        "name": "Remove matching keys from the session keyring tree",
                        "content": "keyctl purge <type>\nkeyctl purge [-i] [-p] <type> <desc>\nkeyctl purge -s <type> <desc>\n\nThese  commands  perform  a  depth-first search to find matching keys in the caller's session\nkeyring tree and attempts to unlink them.   The  number  of  keys  successfully  unlinked  is\nprinted at the end.\n\nThe  keyrings  must grant Read and View permission to the caller to be searched, and the keys\nto be removed must also grant View permission.  Keys can only be removed from  keyrings  that\ngrant Write permission.\n\nThe first variant purges all keys of the specified type.\n\nThe  second  variant purges all keys of the specified type that also match the given descrip‐\ntion literally.  The -i flag allows a case-independent match and the -p flag allows a  prefix\nmatch.\n\nThe  third  variant  purges all keys of the specified type and matching description using the\nkey type's comparator in the kernel to match the description.  This permits the key  type  to\nmatch a key with a variety of descriptions.\n"
                    },
                    {
                        "name": "Get persistent keyring",
                        "content": "keyctl getpersistent <keyring> [<uid>]\n\nThis  command gets the persistent keyring for either the current UID or the specified UID and\nattaches it to the nominated keyring.  The persistent keyring's ID will be printed on stdout.\n\nThe kernel will create the keyring if it doesn't exist and every time this command is called,\nwill reset the expiration timeout on the keyring to the value in:\n\n/proc/sys/kernel/keys/persistentkeyringexpiry\n\n(by default three days).  Should the timeout be reached, the persistent keyring will  be  re‐\nmoved and everything it pins can then be garbage collected.\n\nIf  a UID other than the process's real or effective UIDs is specified, then an error will be\ngiven if the process does not have the CAPSETUID capability.\n"
                    },
                    {
                        "name": "Compute a Diffie-Hellman shared secret or public key",
                        "content": "keyctl dhcompute <private> <prime> <base>\n\nThis command computes either a Diffie-Hellman shared secret or the public  key  corresponding\nto the provided private key using the payloads of three keys. The computation is:\n\nbase ^ private (mod prime)\n\nThe  three  inputs  must be user keys with read permission. If the provided base key contains\nthe shared generator value, the public key will be computed.  If the provided base  key  con‐\ntains the remote public key value, the shared secret will be computed.\n\nThe result is printed to stdout as a hex dump.\n\n$ keyctl dhcompute $1 $2 $3\n8 bytes of data in result:\n00010203 04050607\n\n"
                    },
                    {
                        "name": "Compute a Diffie-Hellman shared secret and derive key material",
                        "content": "keyctl dhcomputekdf <private> <prime> <base> <outputlength> <hashtype>\n\nThis command computes a Diffie-Hellman shared secret and derives key material from the shared\nsecret using a key derivation function (KDF).  The shared secret is derived as outlined above\nand  is  input  to  the KDF using the specified hash type. The hash type must point to a hash\nname known to the kernel crypto API.\n\nThe operation derives key material of the length specified by the caller.\n\nThe operation is compliant to the specification of SP800-56A.\n\nThe result is printed to stdout as hex dump.\n"
                    },
                    {
                        "name": "Compute a Diffie-Hellman shared secret and apply KDF with other input",
                        "content": "keyctl dhcomputekdfoi [-x] <private> <prime> <base> <outputlength> <hashtype>\n\nThis command is identical to the command dhcomputekdf to generate a  Diffie-Hellman  shared\nsecret  followed by a key derivation operation. This command allows the caller to provide the\nother input data (OI data) compliant to SP800-56A via stdin.\n\nIf -x is given, then the data passed to stdin is hex-decoded with whitespace being discarded.\n\n"
                    },
                    {
                        "name": "Perform public-key operations with an asymmetric key",
                        "content": "keyctl pkeyquery <key> <pass> [k=v]*\nkeyctl pkeyencrypt <key> <pass> <datafile> [k=v]* > <encfile>\nkeyctl pkeydecrypt <key> <pass> <encfile> [k=v]* > <datafile>\nkeyctl pkeysign <key> <pass> <datafile> [k=v]* > <sigfile>\nkeyctl pkeyverify <key> <pass> <datafile> <sigfile> [k=v]*\n\nThese commands query an asymmetric key, encrypt data with it,  decrypt  the  encrypted  data,\ngenerate  a  signature  over  some  data and verify that signature.  For encrypt, decrypt and\nsign, the resulting data is written to stdout; verify reads the data and the signature  files\nand compares them.\n\n[!]  NOTE  that  the data is of very limited capacity, with no more bits than the size of the\nkey.  For signatures, the caller is expected to digest the actual data and pass in the result\nof the digest as the datafile.  The name of the digest should be specified on the end of  the\ncommand line as \"hash=<name>\".\n\nThe  key ID indicates the key to use; pass is a placeholder for future password provision and\nshould be \"0\" for the moment; datafile is the unencrypted data to be encrypted, signed or  to\nhave  its  signature  checked;  encfile is a file containing encrypted data; and sigfile is a\nfile containing a signature.\n\nA list of parameters in \"key[=val]\" form can be included on the  end  of  the  command  line.\nThese  specify  things  like  the  digest algorithm used (\"hash=<name>\") or the encoding form\n(\"enc=<type>\").\n\nk=`keyctl padd asymmetric \"\" @s <key.pkcs8.der`\nkeyctl pkeyquery $k 0 enc=pkcs1 hash=sha256\nkeyctl pkeyencrypt $k 0 foo.hash enc=pkcs1 >foo.enc\nkeyctl pkeydecrypt $k 0 foo.enc enc=pkcs1 >foo.hash\nkeyctl pkeysign $k 0 foo.hash enc=pkcs1 hash=sha256 >foo.sig\nkeyctl pkeyverify $k 0 foo.hash foo.sig enc=pkcs1 hash=sha256\n\nSee asymmetric-key(7) for more information.\n\n"
                    },
                    {
                        "name": "Change notifications",
                        "content": "keyctl watch [-f<filters>] <key>\nkeyctl watchsession [-f <filters>] [-n <name>] \\\n<notifylog> <gclog> <fd> <prog> [<arg1> <arg2> ...]   keyctl  watchadd  <fd>\n<key>\nkeyctl watchrm <fd> <key>\n\nThe watch command watches a single key, printing notifications to stdout until the key is de‐\nstroyed.   Filters can be employed to cut down the events that will be delivered.  The filter\nstring is a series of letters, each one of which enables a particular event subtype:\n\ni - The key has been instantiated\np - The key has been updated\nl - A link has been added to a keyring\nn - A link has been removed from a keyring\nc - A keyring has been cleared\nr - A key has been revoked\nv - A key has been invalidated\ns - A key has had its attributes changed\n\nThe output of the command looks like:\n\n<keyid> <event> [<aux>]\n\nWhere keyid is the primary subject of the notification, op is the event and aux is  the  sec‐\nondary  key  if there is one (such as link where the primary key is the keyring secondary key\nis the key being linked in to it).  For example:\n\n255913279 link 340681059\n255913279 clr\n\nAn additional notication is generated when a key being watched is garbage collected, e.g.:\n\n255913279 gc\n\nThe watchsession command creates a new session keyring, with name name if given, watches  it\nfor  notifications  and  runs program prog with it.  The program is given the specified argu‐\nments.\n\nA second process is forked off to monitor the notifications.  The output  from  that  is  di‐\nrected  to the files notifylog for most notifications and gclog for key removal notifications\n(which are asynchronous and may be deferred).\n\nThe watchqueue(7) device is exported to the program attached to fd number fd.  This  can  be\npassed by the other two commands.\n\nThe  watchadd  command  adds a watch on key to the watchqueue attached to fd as exported by\nwatchsession and the watchrm caommand removes it.  A watchqueue can handle  multiple  keys\nand even non-keys sources as well.\n\n\n"
                    }
                ]
            },
            "ERRORS": {
                "content": "There are a number of common errors returned by this program:\n\n\"Not a directory\" - a key wasn't a keyring.\n\n\"Requested key not found\" - the looked for key isn't available.\n\n\"Key has been revoked\" - a revoked key was accessed.\n\n\"Key has expired\" - an expired key was accessed.\n\n\"Permission denied\" - permission was denied by a UID/GID/mask combination.\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "keyctl(1), keyctl(2), requestkey(2), keyctl(3), request-key.conf(5), keyrings(7),\nrequest-key(8)\n\nLinux                                        20 Feb 2014                                   KEYCTL(1)",
                "subsections": []
            }
        }
    }
}