Logging in using curl

Prerequisites
  • Access to the switch REST API must be enabled.

CAUTION:

Credential information (user name, password, domain, and authentication tokens) used in curl commands entered at a command-line prompt might be saved in the command history. For security reasons, Hewlett Packard Enterprise recommends that you disable command history before executing commands containing credential information.

Procedure
Use the following curl command to access the login resource of the switch and provide your user name and password as data:

Syntax:

curl -k[ --noproxy <IP-ADDR>] POST 
-c <COOKIE-FILE>
-H 'Content-Type: application/x-www-form-urlencoded'
"https://<IP-ADDR>/rest/v1/login"
--data 'username=<USER-NAME>&password=<PASSWORD>'
-k

Specifies that the curl program not attempt to verify the server certificate against the list of certificate authorities included with the curl software.

The switch uses self-signed certificates. By default, the curl program attempts to verify certificates against its list of certificate authorities, and attempts to verify self-signed certificates fail. Therefore you must use the –k option to disable attempts to verify self-signed certificates against a certificate authority.

--noproxy <IP-ADDR>

Optional. The --noproxy option is appropriate where execution of curl commands does not need a proxy to access the applications. If your network is configured to require a proxy to access applications, use the --proxy option. <IP-ADDR> specifies the IP address or hostname of the switch.

-c <COOKIE-FILE>

Specifies the file in which to store the session cookie. This session cookie is required when you execute subsequent curl commands.

<USER-NAME>

Specifies the user name.

<PASSWORD>

Specifies the password for the user.

NOTE:

Although it is possible to pass the user name and password information as a query string in the login URI, system logs save the accessed URI in cleartext in log entries. Hewlett Packard Enterprise recommends that you pass the credential information as data instead of in the URI when using programs such as curl to log in to the switch.

Example:

$ curl --noproxy 192.0.2.5 -k POST \
-c /tmp/auth_cookie \
-H 'Content-Type: application/x-www-form-urlencoded' \
"https://192.0.2.5/rest/v1/login" \
--data 'username=admin&password=admin'