본문 바로가기
조회 수 4844 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

+ - Up Down Comment Print
?

단축키

Prev이전 문서

Next다음 문서

+ - Up Down Comment Print

http://www.howtogeek.com/howto/30184/10-ways-to-generate-a-random-password-from-the-command-line/


Generate a Random Password

For any of these random password commands, you can either modify them to output a different password length, or you can just use the first x characters of the generated password if you don’t want such a long password. Hopefully you’re using a password manager like LastPass anyway so you don’t need to memorize them.

This method uses SHA to hash the date, runs through base64, and then outputs the top 32 characters.

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

This method used the built-in /dev/urandom feature, and filters out only characters that you would normally use in a password. Then it outputs the top 32.

< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-32};echo;

This one uses openssl’s rand function, which may not be installed on your system. Good thing there’s lots of other examples, right?

openssl rand -base64 32

This one works a lot like the other urandom one, but just does the work in reverse. Bash is very powerful!

tr -cd '[:alnum:]' < /dev/urandom | fold -w30 | head -n1

Here’s another example that filters using the strings command, which outputs printable strings from a file, which in this case is the urandom feature.

strings /dev/urandom | grep -o '[[:alnum:]]' | head -n 30 | tr -d '\n'; echo

Here’s an even simpler version of the urandom one.

< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c6

This one manages to use the very useful dd command.

dd if=/dev/urandom bs=1 count=32 2>/dev/null | base64 -w 0 | rev | cut -b 2- | rev

You can even create a random left-hand password, which would let you type your password with one hand.

</dev/urandom tr -dc '12345!@#$%qwertQWERTasdfgASDFGzxcvbZXCVB' | head -c8; echo ""

If you’re going to be using this all the time, it’s probably a better idea to put it into a function. In this case, once you run the command once, you’ll be able to use randpw anytime you want to generate a random password. You’d probably want to put this into your ~/.bashrc file.

randpw(){ < /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-16};echo;}

You can use this same syntax to make any of these into a function—just replace everything inside the { }

And here’s the easiest way to make a password from the command line, which works in Linux, Windows with Cygwin, and probably Mac OS X. I’m sure that some people will complain that it’s not as random as some of the other options, but honestly, it’s random enough if you’re going to be using the whole thing.

date | md5sum

Yeah, that’s even easy enough to remember.


Title
List of Articles
번호 제목 글쓴이 날짜 조회 수
448 How to install Java on linux with no Internet connectivity (using local repository) Hojung 2015.12.22 3942
447 How to install tcpreplay on CentOS 6.5 Hojung 2015.08.21 8957
446 Install et131x network interface driver in CentOS 6 (LW25-BDUO3) file Hojung 2015.07.03 5079
445 How to find CentOS and kernel version Hojung 2015.04.30 4399
444 MD5 Test Hojung 2015.04.01 4582
443 MAC times in Linux (atime, mtime, ctime, crtime, touch, stat, debugfs) Hojung 2015.01.13 5533
442 How to generate a key with passphrase Hojung 2014.11.22 5721
441 Most Common OpenSSL Commands Hojung 2014.11.21 6205
440 How to use screen command Hojung 2014.11.17 4618
439 snorby (on testing) Hojung 2014.11.17 7425
438 APM (Apache + PHP + MySQL) with phpmyadmin in CentOS VM Hojung 2014.11.16 5540
» 10 Ways to Generate a Random Password from the Command Line Hojung 2014.11.16 4844
436 How to increase the size of a Linux LVM by adding a new disk file Hojung 2014.11.14 5047
435 Configuring logrotate for Rails logs file Hojung 2014.11.13 5491
434 Installing Splunk on CentOS file Hojung 2014.10.31 7388
433 Web performance test with ab (ruby web, dd, ab) file Hojung 2014.10.01 6357
432 Web performance test with Pylot (ruby web, dd, pylot) file Hojung 2014.10.01 5894
431 Install and Configure NTP to Synchronize The System Clock (ntpd, ntpdate) Hojung 2014.09.17 5408
430 How to disable IPv6 in CentOS 6 Hojung 2014.09.04 5534
429 IDS with snort in CentOS (Snort, Barnyard2) Hojung 2014.08.19 8978
Board Pagination ‹ Prev 1 2 3 4 5 6 7 8 9 10 ... 23 Next ›
/ 23

Designed by sketchbooks.co.kr / sketchbook5 board skin

나눔글꼴 설치 안내


이 PC에는 나눔글꼴이 설치되어 있지 않습니다.

이 사이트를 나눔글꼴로 보기 위해서는
나눔글꼴을 설치해야 합니다.

설치 취소

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5