cPanel API 2 Functions - SSH::importkey
Description
This function imports an SSH key. This function will overwrite an existing key with the same name as the imported key.
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=import&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
LiveAPI PHP Class
$cpanel
=
new
CPANEL();
$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'
)
);
LiveAPI Perl Module
my
$cpliveapi
= Cpanel::LiveAPI->new();
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'
}
);
cPanel Tag System (deprecated)
Warning:
In cPanel & WHM version 11.30 and later, cPanel tags are deprecated. We strongly recommend that you only use theLiveAPI system to call the cPanel APIs.
cPanel API 2 calls that use cPanel tags vary widely in code syntax and in their output. For more information, read ourDeprecated cPanel Tag Usage documentation. Examples are only present in order to help developers move from the old cPanel tag system to our LiveAPI.
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
|
Output (JSON)
{
"cpanelresult"
: {
"apiversion"
:
2
,
"func"
:
"importkey"
,
"data"
: [
{
"name"
:
"bob"
,
}
],
"event"
: {
"result"
:
1
},
"module"
:
"SSH"
}
}
Parameters
Parameter
|
Type
|
Description
|
Possible values
|
Example
|
key
|
string
|
Required
The contents of the key file.
|
A valid SSH key file.
|
|
name
|
string
|
The SSH key's filename.
If you do not use either the name or passparameters, the function returns all of the account's keys.
|
A valid string.
Note:
The following names are reserved:
- config
- known_hosts
- authorized_keys
- environment
- rc
- identity
|
user
|
pass
|
string
|
The SSH key's password.
If you do not use either the name or passparameters, 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.
Note:
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
|
- 0 Users Found This Useful
Related Articles
User Preferences
For cPanel & WHM version 58
Overview
This document outlines how to access your cPanel...
What is cPanelID?
In This Article:
Overview
ServicesHow to get a cPanelID
cPanelID
External...