Using "mkpasswd" to Generate Passwords

Ansible requires passwords to be set in a certain format. In this guide, you'll learn how to use Docker to create an Ubuntu 22.04 container on your local machine, install mkpasswd, then use mkdpasswd to generate the secure hashes you need.

Create a temporary container

We'll use the power of Docker to run a fresh Ubuntu 22.04 instance. We'll install mkpasswd on it, then once we close the container, the container will automatically destroy itself.

Run a temporary docker container

docker run --rm -it ubuntu:22.04 bash

Once inside the container, run this command to install mkpasswd.

Install `mkpasswd`

apt -y update && apt -y install whois

Now that mkpasswd is installed, we can use the command to create a password hash.

Use `mkpasswd` to generate a hash

mkpasswd mysupersecretpassword

That should return a value similar to this:

Example password hash

$y$j9T$x/n10Dsflcgy34aO5SPq9fkyHH/ci8iUgQ1$64V3lskdc6jYhAfD/2SPIWFHV.B

You will want to use the generated password hash above to set in your .spin.yml for users.password.