Enable SSH key for server

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.
SecurityBasicAuth
Request
query Parameters
authorize
required
integer

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

  • 1 — Authorize.
  • 0 — Do not authorize.
Enum: 1 0
Example: authorize=1
file
required
string

The public SSH key file's name.

Note:

  • This file must exist in the /root/.ssh directory.
  • If you call both the file and the text parameters, the function ignores the file parameter.
Example: file=sshkey.pub
text
required
string

The text of the SSH public key file.

Note:

  • If you call both the file and the text parameters, the function ignores the file parameter.
Example: text=ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCys7JbGhkAZ8E4Pmq8D4EBm1UedKK2oMhs3RVIEFRJX6S86Itw6Qmhds62LNGrxuVL11W6v25+maIiBhXnslyQpd838tHyAC7J/SJojDid8acovX/4xgJQaJHLAh9tLgyQXnNhIxIGJ4nVZ+8OqM2Vb1Cps+E5H17ivG07PXnVPEvwMaeWkm2DnGgSy5kmjVpNKlj9GWFCn/SJd7up7QnbGKoz87pxKDs3esp+ziuPEAJHLeXnKHWPVukQgtRUpUBdqkCvu5hUkhpaiWmBR8yxajkxbSObPw+ZkELhmm+fQseOfEbrwToMRJCO7gAKwBtNi7OhyFM7YFrvdo0xh6cn
options
string

A comma-separated list of options to include with the public SSH key. For a list of options, read the OpenBSD manaual.

This parameter defaults to no options.

Example: options=agent-forwarding,cert-authority
Responses
200

HTTP Request was successful.

Response Schema: application/json
object
object
get/authorizesshkey
Request samples
whmapi1 --output=jsonpretty \
  authorizesshkey \
  file='sshkey.pub' \
  text='ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCys7JbGhkAZ8E4Pmq8D4EBm1UedKK2oMhs3RVIEFRJX6S86Itw6Qmhds62LNGrxuVL11W6v25+maIiBhXnslyQpd838tHyAC7J/SJojDid8acovX/4xgJQaJHLAh9tLgyQXnNhIxIGJ4nVZ+8OqM2Vb1Cps+E5H17ivG07PXnVPEvwMaeWkm2DnGgSy5kmjVpNKlj9GWFCn/SJd7up7QnbGKoz87pxKDs3esp+ziuPEAJHLeXnKHWPVukQgtRUpUBdqkCvu5hUkhpaiWmBR8yxajkxbSObPw+ZkELhmm+fQseOfEbrwToMRJCO7gAKwBtNi7OhyFM7YFrvdo0xh6cn' \
  authorize='1'
Response samples
application/json
{
  • "data": {
    • "authorized": 1,
    • "file": "sshkey.pub"
    },
  • "metadata": {
    • "command": "authorizesshkey",
    • "reason": "OK",
    • "result": 1,
    • "version": 1
    }
}