Password Encryption for automation scripts

Password Encryption for automation scripts

For automation you may need to encrypt passwords for security reason. For example with ZTP/ansible or with ZPE Cloud you may have scripts to change a password. Openssl is the tool to use.

The example below will encrypt your password with MD5-based password algorithm:
echo 'ImanId10t' | openssl passwd -1 -stdin
will return:
$1$c0P8Aqls$5XDSdYdJ4IJj1mR4fTPEG.
Another example with a salt:
echo 'ImanId10t' | openssl passwd -1 -salt zpe -stdin
This one is a SHA512 password algorithm with a salt:
echo 'ImanId10t' | openssl passwd -6 -salt zpe password

The "passwd -1" is for using MD5-based password algorithm. See below for all the encryption list
In the returned encrypted password:
      - the first part: $1 is to specify the encryption used. In our case: MD5-based password algorithm
      - the second part after the second $ is the encrypted password

Once you have the encrypted password you can then use it in your automation scripts.
The example below will change the user1 password with the encrypted password:
echo 'user1:\$1\$c0P8Aqls\$5XDSdYdJ4IJj1mR4fTPEG.' | /usr/sbin/chpasswd -e
NOTE: You may need to put a "\" in front of special characters


openssl passwd --help
Usage: passwd [options]
Valid options are:

-help

Display this summary

-in infile

Read passwords from file

-noverify

Never verify when reading password from terminal

-quiet

No warnings

-table

Format output as table

-reverse

Switch table columns

-salt val

Use provided salt

-stdin

Read passwords from stdin

-6

SHA512 based password algorithm

-5

SHA256 based password algorithm

-apr1

MD5 based password algorithm, Apache variant

-1

MD5 based password algorithm

-aixmd5

AIX MD5 based password algorithm

-crypt

Standard Unix password algorithm (default)

- rand val

Load the file(s) into the random number generator

- writerand outfile

Write random data to the specified file





    • Related Articles

    • Changing the Password

      One can change the admin password with any of these methods. Method 1: Login as admin and click on admin link( drop down ) on the top right corner Click Change Password Enter your current and New passwords Click Save  Method 2: Navigate to ...
    • How to Recover/Reset Password of Admin or Root Users

      Case #1 The admin password was changed and you don’t remember it, but root password is still the default. Log in as root via NodeGrid console port, type its default password root. At the shell prompt, type passwd admin and enter the new password. You ...
    • Changing the Password

    • Nodegrid RESTful API's: How to paginate requests

      Nodegrid's RESTful API's: How to paginate requests Nodegrid's RESTful API's support pagination. Pagination is used to break down larger datasets into smaller pages. Each page is then requested separately. This helps to improve the system performance. ...
    • How to Add Users to NodeGrid

      Adding new users via WebUI Log in as admin to the NodeGrid WebUI Click on Local Accounts A list of all users will be displayed on the User Names screen; Click on Add and the Local User Information screen will be displayed; Type a new user name and ...