You can find our user documentation at docs.cpanel.net.

Check out our new API beta site!

Child pages
  • WHM API 1 Functions - authorizesshkey
Skip to end of metadata
Go to start of metadata

Description

This function authorizes a public SSH key to access the server. When you call this function, it adds the key to the /root/.ssh/authorized_keys file.

Warning:

  • Do not transfer private keys over insecure ports. 
  • Only root and root-enabled resellers can use this function, and it only affects the root public SSH keys. To perform this function on a regular user account, call the cPanel API 2 SSH::authkey function via the WHM API. For more information, read our Use WHM API to Call cPanel API and UAPI documentation.

Examples 


 JSON API
https://hostname.example.com:2087/cpsess##########/json-api/authorizesshkey?api.version=1&file=sshkey.pub&authorize=1&options=agent-forwarding,cert-authority
 XML API
https://hostname.example.com:2087/cpsess##########/xml-api/authorizesshkey?api.version=1&file=sshkey.pub&authorize=1&options=agent-forwarding,cert-authority
 Command Line
whmapi1 authorizesshkey file=sshkey.pub authorize=1 options=agent-forwarding,cert-authority


Notes:

  • Unless otherwise noted, you must URI-encode values.
  • For more information and additional output options, read our Guide to WHM API 1 documentation or run the whmapi1 --help command.
  • If you run CloudLinux™, you must use the full path of the whmapi1 command:

    /usr/local/cpanel/bin/whmapi1

 Output (JSON)
{
   "metadata" : {
      "result" : 1,
      "reason" : "OK",
      "version" : 1,
      "command" : "authorizesshkey"
   },
   "data" : {
      "file" : "sshkey.pub",
      "authorized" : 1
   }
}
 Output (XML)
<result>
    <metadata>
        <result>1</result>
        <version>1</version>
        <reason>OK</reason>
        <command>authorizesshkey</command>
    </metadata>
    <data>
        <file>sshkey.pub</file>
        <authorized>1</authorized>
    </data>
</result>


Note:

Use WHM's API Shell interface (WHM >> Home >> Development >> API Shell) to directly test WHM API calls.

Parameters

Note:

  • You must include either the file or the text parameter.
  • If you call both the file and the text parameters, the function ignores the file parameter.
ParameterTypeDescriptionPossible valuesExample
filestring

Required

The public SSH key file's name. 

Note:

This file must exist in the /root/.ssh directory.

A valid file name.

sshkey.pub


textstring

Required

The text of the SSH public key file.

A valid SSH key.

 Click to view...
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCys7JbGhkAZ8E4Pmq8D4EBm1UedKK2oMhs3RVIEFRJX6S86Itw6Qmhds62LNGrxuVL11W6v25+maIiBhXnslyQpd838tHyAC7J/SJojDid8acovX/4xgJQaJHLAh9tLgyQXnNhIxIGJ4nVZ+8OqM2Vb1Cps+E5H17ivG07PXnVPEvwMaeWkm2DnGgSy5kmjVpNKlj9GWFCn/SJd7up7QnbGKoz87pxKDs3esp+ziuPEAJHLeXnKHWPVukQgtRUpUBdqkCvu5hUkhpaiWmBR8yxajkxbSObPw+ZkELhmm+fQseOfEbrwToMRJCO7gAKwBtNi7OhyFM7YFrvdo0xh6cn
authorizeBoolean

Required

Whether to authorize the public SSH key to access the server.

  • 1 — Authorize.
  • 0 — Do not authorize.
1
optionsstring

A comma-separated list of options to include with the public SSH key.

This parameter defaults to no options.

For a list of valid options, read the OpenBSD manual.agent-forwarding,cert-authority

Returns

ReturnTypeDescriptionPossible valuesExample
filestring

The public SSH key file's name.

A valid filename.
sshkey.pub

authorized

Boolean

Whether the public SSH key has authorization.

  • 1 — Authorized.
  • 0Not authorized.
1