cPanel API 2 Functions - SSH::importkey

Warning:

The cPanel API 2 system is deprecated. We strongly recommend that you use UAPI instead of cPanel API 2.


Description

This function imports an SSH key.

Warnings:
  • This function will overwrite any existing keys that use the same name as the imported key.
  • We strongly recommend that you use UAPI instead of cPanel API 2. However, no equivalent UAPI function exists.

Examples


WHM API (JSON)

 https://hostname.example.com:2087/cpsess###########/json-api/cpanel?cpanel_jsonapi_user=user&cpanel_jsonapi_apiversion=2&cpanel_jsonapi_module=SSH&cpanel_jsonapi_func=importkey&key=-----BEGIN%20RSA%20PRIVATE%20KEY-----%5CnProc-Type%3A%204%2CENCRYPTED%5CnDEK-Info%3A%20DES-EDE3-CBC%2C8B36FD4196F9015D%5Cn%5CnRttykPEmZu4jTfPzIZkSsfkZaTTXOt3Ho%2BJCqG6HplaCm%2FKibiEBkVUXkC4QLrUL%5CnB%2B%2FifvjN%2BiXYwiYvXLSB5EnVyEuPIjFnnugSIN1Cp84mUlRSyO4DfhPTdWLwr5tP%5CnIYqzpB0cxL2zqX%2BGB8BCx%2FS2NDQ%2FnQWMepKZrod3kasza%2FH580F5lO3fJlU%2B3WQb%5CnlYqgOMKeDcatCDgrlc%2FS%2Fqz6xjk%2BHrivnZL%2BEQTS0av8ZtWEjsjCwvn9N0Gb1TOW%5Cni8uv%2FhPpu6SVZkLUb7RUsIEXW44%2B%2FSa6PsSjTq5SLu8C%2FDV8K6x63R%2FRszlES%2BXi%5CnDbl%2BIGPY2JGPjBnje3X4D8QwzEFzFMx24VuwglT21IbYmhyrc5h0oye1mVLGwbV9%5Cn%2FxolX9iQEjRMzB67zHTU%2F6WfVPnYFSiSoBSCwcgtOl4R4ZLMby5sdXycKME4wCyJ%5Cn3UFkrI6NH4H0FGte%2BMFjZ0SwUy18IO%2Fpxs%2FhScg0ZUk4LbpiA9feB%2FImkxrdW19t%5Cn9b26RWHI%2FK4tT4NUDSB%2BT08UM0Hb%2BQ2%2BMbYLDrANTvb4NxqazlJsa%2BrwYD3X8%2BHj%5CneTxwSZSrVHJkog4fUfbZavYHiXgkSws1TXP9JfqOwn3D4eltscOS%2B%2BTvATTgo3Qr%5CnXpAmCQ8mfeZJzVDPIwP7XO3EBg3uDqfVe9gPh%2FQlmTwYOBYHMk3dWNbxlcuovXvC%5CnCFwjJHD8FGhBsC%2BEJhscRYW9YfVyuIcb3arZn%2BNk6a8p%2B%2BnLu8yojh5P6iGJviMq%5Cn2Pkk2tgu6Cshy66tFJy0joDo5jsXh5d4WEB1aKojrLI%3D%5Cn-----END%20RSA%20PRIVATE%20KEY-----&name=user&pass=12345luggage
Note:

For more information, read our Calls from the WHM API documentation.


LiveAPI PHP Class

$cpanel = new CPANEL(); // Connect to cPanel - only do this once.

// Import an SSH key
$import_key = $cpanel->api2(
    'SSH', 'importkey',
  array(
        'key' => '-----BEGIN RSA PRIVATE KEY-----\nProc-Type: 4,ENCRYPTED\nDEK-Info: DES-EDE3-CBC,8B36FD4196F9015D\n\nRttykPEmZu4jTfPzIZkSsfkZaTTXOt3Ho+JCqG6HplaCm/KibiEBkVUXkC4QLrUL\nB+/ifvjN+iXYwiYvXLSB5EnVyEuPIjFnnugSIN1Cp84mUlRSyO4DfhPTdWLwr5tP\nIYqzpB0cxL2zqX+GB8BCx/S2NDQ/nQWMepKZrod3kasza/H580F5lO3fJlU+3WQb\nlYqgOMKeDcatCDgrlc/S/qz6xjk+HrivnZL+EQTS0av8ZtWEjsjCwvn9N0Gb1TOW\ni8uv/hPpu6SVZkLUb7RUsIEXW44+/Sa6PsSjTq5SLu8C/DV8K6x63R/RszlES+Xi\nDbl+IGPY2JGPjBnje3X4D8QwzEFzFMx24VuwglT21IbYmhyrc5h0oye1mVLGwbV9\n/xolX9iQEjRMzB67zHTU/6WfVPnYFSiSoBSCwcgtOl4R4ZLMby5sdXycKME4wCyJ\n3UFkrI6NH4H0FGte+MFjZ0SwUy18IO/pxs/hScg0ZUk4LbpiA9feB/ImkxrdW19t\n9b26RWHI/K4tT4NUDSB+T08UM0Hb+Q2+MbYLDrANTvb4NxqazlJsa+rwYD3X8+Hj\neTxwSZSrVHJkog4fUfbZavYHiXgkSws1TXP9JfqOwn3D4eltscOS++TvATTgo3Qr\nXpAmCQ8mfeZJzVDPIwP7XO3EBg3uDqfVe9gPh/QlmTwYOBYHMk3dWNbxlcuovXvC\nCFwjJHD8FGhBsC+EJhscRYW9YfVyuIcb3arZn+Nk6a8p++nLu8yojh5P6iGJviMq\n2Pkk2tgu6Cshy66tFJy0joDo5jsXh5d4WEB1aKojrLI=\n-----END RSA PRIVATE KEY-----',
        'name' => 'user',
        'pass' => '12345luggage'
   )
);
Note:

For more information, read our Guide to the LiveAPI System.


LiveAPI Perl Module

my $cpliveapi = Cpanel::LiveAPI->new(); # Connect to cPanel - only do this once.

# Import an SSH key
my $import_key = $cpliveapi->api2(
    'SSH', 'importkey'
   {
        'key' => '-----BEGIN RSA PRIVATE KEY-----\nProc-Type: 4,ENCRYPTED\nDEK-Info: DES-EDE3-CBC,8B36FD4196F9015D\n\nRttykPEmZu4jTfPzIZkSsfkZaTTXOt3Ho+JCqG6HplaCm/KibiEBkVUXkC4QLrUL\nB+/ifvjN+iXYwiYvXLSB5EnVyEuPIjFnnugSIN1Cp84mUlRSyO4DfhPTdWLwr5tP\nIYqzpB0cxL2zqX+GB8BCx/S2NDQ/nQWMepKZrod3kasza/H580F5lO3fJlU+3WQb\nlYqgOMKeDcatCDgrlc/S/qz6xjk+HrivnZL+EQTS0av8ZtWEjsjCwvn9N0Gb1TOW\ni8uv/hPpu6SVZkLUb7RUsIEXW44+/Sa6PsSjTq5SLu8C/DV8K6x63R/RszlES+Xi\nDbl+IGPY2JGPjBnje3X4D8QwzEFzFMx24VuwglT21IbYmhyrc5h0oye1mVLGwbV9\n/xolX9iQEjRMzB67zHTU/6WfVPnYFSiSoBSCwcgtOl4R4ZLMby5sdXycKME4wCyJ\n3UFkrI6NH4H0FGte+MFjZ0SwUy18IO/pxs/hScg0ZUk4LbpiA9feB/ImkxrdW19t\n9b26RWHI/K4tT4NUDSB+T08UM0Hb+Q2+MbYLDrANTvb4NxqazlJsa+rwYD3X8+Hj\neTxwSZSrVHJkog4fUfbZavYHiXgkSws1TXP9JfqOwn3D4eltscOS++TvATTgo3Qr\nXpAmCQ8mfeZJzVDPIwP7XO3EBg3uDqfVe9gPh/QlmTwYOBYHMk3dWNbxlcuovXvC\nCFwjJHD8FGhBsC+EJhscRYW9YfVyuIcb3arZn+Nk6a8p++nLu8yojh5P6iGJviMq\n2Pkk2tgu6Cshy66tFJy0joDo5jsXh5d4WEB1aKojrLI=\n-----END RSA PRIVATE KEY-----',
        'name' => 'user',
        'pass' => '12345luggage'
    }
);
Note:

For more information, read our Guide to the LiveAPI System.


cPanel Tag System (deprecated)

Warnings:
  • cPanel tags are deprecated . We strongly recommend that you only use the LiveAPI system to call the cPanel APIs. Examples are only present in order to help developers move from the old cPanel tag system to our LiveAPI .
  • cPanel API 2 calls that use cPanel tags vary in code syntax and in their output.
  • For more information, read our Deprecated cPanel Tag Usage documentation.

Command Line

cpapi2 --user=username SSH importkey key=-----BEGIN RSA PRIVATE KEY-----\nProc-Type: 4,ENCRYPTED\\nDEK-Info: DES-EDE3-CBC,8B36FD4196F9015D\\n\\nRttykPEmZu4jTfPzIZkSsfkZaTTXOt3Ho+JCqG6HplaCm/KibiEBkVUXkC4QLrUL\\nB+/ifvjN+iXYwiYvXLSB5EnVyEuPIjFnnugSIN1Cp84mUlRSyO4DfhPTdWLwr5tP\nIYqzpB0cxL2zqX+GB8BCx/S2NDQ/nQWMepKZrod3kasza/H580F5lO3fJlU+3WQb\nlYqgOMKeDcatCDgrlc/S/qz6xjk+HrivnZL+EQTS0av8ZtWEjsjCwvn9N0Gb1TOW\ni8uv/hPpu6SVZkLUb7RUsIEXW44+/Sa6PsSjTq5SLu8C/DV8K6x63R/RszlES+Xi\nDbl+IGPY2JGPjBnje3X4D8QwzEFzFMx24VuwglT21IbYmhyrc5h0oye1mVLGwbV9\n/xolX9iQEjRMzB67zHTU/6WfVPnYFSiSoBSCwcgtOl4R4ZLMby5sdXycKME4wCyJ\n3UFkrI6NH4H0FGte+MFjZ0SwUy18IO/pxs/hScg0ZUk4LbpiA9feB/ImkxrdW19t\n9b26RWHI/K4tT4NUDSB+T08UM0Hb+Q2+MbYLDrANTvb4NxqazlJsa+rwYD3X8+Hj\neTxwSZSrVHJkog4fUfbZavYHiXgkSws1TXP9JfqOwn3D4eltscOS++TvATTgo3Qr\nXpAmCQ8mfeZJzVDPIwP7XO3EBg3uDqfVe9gPh/QlmTwYOBYHMk3dWNbxlcuovXvC\nCFwjJHD8FGhBsC+EJhscRYW9YfVyuIcb3arZn+Nk6a8p++nLu8yojh5P6iGJviMq\n2Pkk2tgu6Cshy66tFJy0joDo5jsXh5d4WEB1aKojrLI=\n-----END RSA PRIVATE KEY----- name=user pass=12345luggage
Notes:
  • You must URI-encode values.
  • username represents your account-level username.
  • You must include the --user=username option.
  • For more information and additional output options, read our Guide to cPanel API 2 documentation or run the cpapi2 --help command.
  • If you run CloudLinux™, you must use the full path of the cpapi2 command:
    /usr/local/cpanel/bin/cpapi2

Output (JSON)

{
    "cpanelresult": {
        "apiversion": 2,
        "func": "importkey",
        "data": [{
            "name": "bob"
        }],
        "event": {
            "result": 1
        },
        "module": "SSH"
    }
}
Note:

Use cPanel's API Shell interface (cPanel >> Home >> Advanced >> API Shell) to directly test cPanel API calls.


Parameters

Parameter Type Description Possible values Example
key string

Required

The contents of the key file.

A valid SSH key file. -----BEGIN RSA PRIVATE KEY-----\nProc-Type: 4,ENCRYPTED\nDEK-Info: DES-EDE3-CBC,8B36FD4196F9015D\n\nRttykPEmZu4jTfPzIZkSsfkZaTTXOt3Ho+JCqG6HplaCm/KibiEBkVUXkC4QLrUL\nB+/ifvjN+iXYwiYvXLSB5EnVyEuPIjFnnugSIN1Cp84mUlRSyO4DfhPTdWLwr5tP\nIYqzpB0cxL2zqX+GB8BCx/S2NDQ/nQWMepKZrod3kasza/H580F5lO3fJlU+3WQb\nlYqgOMKeDcatCDgrlc/S/qz6xjk+HrivnZL+EQTS0av8ZtWEjsjCwvn9N0Gb1TOW\ni8uv/hPpu6SVZkLUb7RUsIEXW44+/Sa6PsSjTq5SLu8C/DV8K6x63R/RszlES+Xi\nDbl+IGPY2JGPjBnje3X4D8QwzEFzFMx24VuwglT21IbYmhyrc5h0oye1mVLGwbV9\n/xolX9iQEjRMzB67zHTU/6WfVPnYFSiSoBSCwcgtOl4R4ZLMby5sdXycKME4wCyJ\n3UFkrI6NH4H0FGte+MFjZ0SwUy18IO/pxs/hScg0ZUk4LbpiA9feB/ImkxrdW19t\n9b26RWHI/K4tT4NUDSB+T08UM0Hb+Q2+MbYLDrANTvb4NxqazlJsa+rwYD3X8+Hj\neTxwSZSrVHJkog4fUfbZavYHiXgkSws1TXP9JfqOwn3D4eltscOS++TvATTgo3Qr\nXpAmCQ8mfeZJzVDPIwP7XO3EBg3uDqfVe9gPh/QlmTwYOBYHMk3dWNbxlcuovXvC\nCFwjJHD8FGhBsC+EJhscRYW9YfVyuIcb3arZn+Nk6a8p++nLu8yojh5P6iGJviMq\n2Pkk2tgu6Cshy66tFJy0joDo5jsXh5d4WEB1aKojrLI=\n-----END RSA PRIVATE KEY-----
name string

The SSH key's filename.

If you do not use either the name or pass parameters, the function returns all of the account's keys.

A valid string.

You cannot use the following values:

  • config
  • known_hosts
  • authorized_keys
  • environment
  • rc
  • identity

This function will overwrite any existing keys that use the same name as the imported key.

user
pass string

The SSH key's password.

If you do not use either the name or pass parameters, the function returns all of the account's keys.

A secure password. 12345luggage

Returns

Return Type Description Possible values Example
name string The SSH key's name. A valid filename. user
reason string

A reason for failure.

This function only returns a reason value if it failed.

A string that describes the error.

This is an error message.
result Boolean

Whether the function succeeded.

  • 1 — The function succeeded.
  • 0 — The function failed.
1