Skip to content

Instantly share code, notes, and snippets.

@scarolan
Created April 12, 2018 17:43
Show Gist options
  • Save scarolan/ac6bc8e2e0d1933a1ac14ba7ab2819ec to your computer and use it in GitHub Desktop.
Save scarolan/ac6bc8e2e0d1933a1ac14ba7ab2819ec to your computer and use it in GitHub Desktop.
Rotate a local Linux password, store the new password in HashiCorp Vault
#!/bin/sh
# Script for rotating passwords on the local machine.
# Make sure and store VAULT_TOKEN as an environment variable before running this.
USERNAME=$1
PASSLENGTH=$2
VAULTURL=$3
NEWPASS=$(openssl rand -base64 $PASSLENGTH)
JSON="{ \"data\": { \"root\": \"$NEWPASS\" } }"
# First commit the new password to vault
curl -H "X-Vault-Token: $VAULT_TOKEN" -X POST --data "$JSON" $VAULTURL/v1/secret/data/linux/$(hostname)_rootpw
# Then set it on the local machine
echo $NEWPASS | passwd root --stdin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment