Showing posts with label password. Show all posts
Showing posts with label password. Show all posts

Wednesday, April 22, 2015

How to set a password from command line in linux bash?

If you need to set a password from a command line automatically, you can use the following script:

echo myPassword | passwd myUser --stdin

This will ensure your password is send via pipe into passwd and set appropriately. It can be useful when you need to assign same password on different servers, so you can run this command remotely, over ssh.

Friday, November 7, 2014

Random password in bash

Sometimes you may need to generate some random password. Bash can help you with that task. For any of the commands below you can modify them to adjust to your needs, i.e. modify the length or the logic.

16-character-long password based on date and base64/SHA encoding:

date +%s | base64 | sha256sum | head -c 16 ; echo

Another example using built-in /dev/urandom command:

< /dev/urandom tr -dc a-zA-Z-0-9 | head -c 16 ; echo;

Now the simplest command, which will work in any environment. 

date | md5sum

date | md5sum | head -c 8