Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bcrypt for BASH Shell?

I'm searching for a way to hash a password using BCRYPT in a BASH script. I've searched high and low, and googled all the things ... the closest I've come is maybe an implementation using openssl, but the method is still unclear.

I am in a closed system with no external access, and python is not installed.

I am proficient at writing in BASH and am using GNU Bash, version 4.1.2(2)-release (x86_64-redhat-linux-gnu).

Interested in suggestions for a solution in pure BASH/AWK or any other implementation native to a common RHEL Shell.

Perl is installed, but I'd prefer to stay away from that option, least of which, I don't know Perl ... there's a social stigma associated with Perl ... (hahaha.c)

Thanks!

like image 844
misteralexander Avatar asked Nov 30 '17 18:11

misteralexander


People also ask

Does Linux use bcrypt?

The bcrypt function is the default password hash algorithm for OpenBSD and was the default for some Linux distributions such as SUSE Linux.

Is bcrypt still the best?

A lot of your research is correct and still applies in 2021, so it is still secure to use BCrypt (which usually generates its own random salt for each password). Good password hashing algorithms are Argon2, SCrypt and BCrypt, they all offer a cost factor which controls the necessary time.

Which is better SHA256 or bcrypt?

TL;DR; SHA1, SHA256, and SHA512 are all fast hashes and are bad for passwords. SCRYPT and BCRYPT are both a slow hash and are good for passwords. Always use slow hashes, never fast hashes.


1 Answers

This is what I use

leo@xxx:~$ htpasswd -nbBC 10 USER topsecret
USER:$2y$10$vDtCxgJ4DIZ1itAAq6NDkedmaDFHlPdlpLY.EiEa3QBXHnH0oLatW

Please note the salt prefix (i.e. $2a or $2y) could be different in different system/platform.

My computer

leo@xxx:~$ uname -a
Linux xxx 5.0.0-37-generic #40~18.04.1-Ubuntu SMP Thu Nov 14 12:06:39 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
like image 54
leo Avatar answered Oct 23 '22 19:10

leo