Page tree
Skip to end of metadata
Go to start of metadata

 

Description

This function authorizes a key to access the server via SSH.

Warning:

  • Do not transfer private keys over insecure ports. 
  • Only the root account can use this function, and it only affects the root keys. To perform this function on a regular user account, call the cPanel API 2 SSH::authkey function through the WHM API.

Examples 


 JSON API
https://hostname.example.com:2087/cpsess##########/json-api/authorizesshkey?api.version=1&user=username&file=%2Fhome%2Fusername%2Fsshkey&authorize=1
 XML API
https://hostname.example.com:2087/cpsess##########/xml-api/authorizesshkey?api.version=1&user=username&file=%2Fhome%2Fusername%2Fsshkey&authorize=1
 Command Line
whmapi1 authorizesshkey user=username file=%2Fhome%2Fusername%2Fsshkey authorize=1

Notes:

  • 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. 
  • We introduced this functionality in cPanel & WHM version 11.52.0.8.

 Output (JSON)
{
  "metadata": {
    "reason": "OK",
    "version": 1,
    "command": "authorizesshkey",
    "result": 1
  },
  "data": {
    "file": "test",
    "authorized": 1
  }
}
 Output (XML)
<result>
    <metadata>
        <result>1</result>
        <version>1</version>
        <reason>OK</reason>
        <command>authorizesshkey</command>
    </metadata>
    <data>
        <file>test</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.

ParameterTypeDescriptionPossible valuesExample
filestringThe SSH key file's name.

An absolute file path.

/home/username/ sshkey

 


 

textstringThe text of the SSH public key file.A valid SSH key.
 Click to view...
ssh-rsa AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB3NzaC1yc2EAAAABIwAAAQEA4fTwKg8fA4Ey5/fwyZdeiWoktiXwx1dAAAAAA
AAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB3NzaC1yc2EAAAABIwAAAQEA4fTwKg8fA4Ey5/fwyZdeiWoktiXwx1dAAAAAA
AAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB3NzaC1yc2EAAAABIwAAAQEA4fTwKg8fA4Ey5/fwyZdeiWoktiXwx1dAAAAAA
AAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB3NzaC1yc2EAAAABIwAAAQEA4fTwKg8fA4Ey5/fwyZdeiWoktiXwx1dAAAAAA
AAAAAAAAAAAA == REPO user@example.com
userstringThe SSH key's username.A valid username.username
authorizeBooleanWhether to authorize the SSH key to access the server.
  • 1 — Authorize.
  • 0 — Do not authorize.
                1
              
optionsstringOptions to include with the SSH key.A valid string.null

 

Returns

ReturnTypeDescriptionPossible valuesExample
filestring

The SSH key file's name.

A valid filename.
TestKey 

authorize

Boolean

Whether the SSH key is authorized to access the server.

  • 1 — Authorized.
  • 0Not authorized.
1