Hide

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.


If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

Hide

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for:

Hide

News

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

Commands tagged openssl from sorted by
Terminal - Commands tagged openssl - 30 results
[ `curl 'http://crl.godaddy.com/gds5-16.crl' 2>/dev/null | openssl crl -inform DER -noout -nextupdate | awk -F= '{print $2}' | xargs -I{} date -d {} +%s` -gt `date -d '8 hours' +%s` ] && echo "OK" || echo "Expires soon"
2014-08-07 17:18:38
User: hufman
Functions: awk date echo xargs
Tags: openssl
0

Downloads a CRL file, determines the expiration time, and checks when it will expire

(read -r passphrase; b58encode 80$( brainwallet_exponent "$passphrase" )$( brainwallet_checksum "$passphrase" ))
4

A bitcoin "brainwallet" is a secret passphrase you carry in the "wallet" of your brain.

The Bitcoin Brainwallet Private Key Calculator calculates the standard base58 encoded bitcoin private key from your "brainwallet" passphrase.

The private key is the most important bitcoin number. All other numbers can be derived from it.

This command uses 3 other functions - all 3 are defined on my user page:

1) brainwallet_exponent() - search for Bitcoin Brainwallet Exponent Calculator

2) brainwallet_checksum() - search for Bitcoin Brainwallet Exponent Calculator

3) b58encode() - search for Bitcoin Brainwallet Base58 Encoder

Do make sure you use really strong, unpredictable passphrases (30+ characters)!

http:brainwallet.org can be used to check the accuracy of this calculator.

function brainwallet_checksum () { (o='openssl sha256 -binary'; p='printf';($p %b "\x80";$p %s "$1"|$o)|$o|sha256sum|cut -b1-8); }
4

A bitcoin "brainwallet" is a secret passphrase you carry in your brain.

The Bitcoin Brainwallet Exponent Calculator is the second of three functions needed to calculate a bitcoin PRIVATE key. Roughly, checksum is the first 8 hex digits of sha256(sha256(0x80+sha256(passphrase)))

Note that this is a bash function, which means you have to type its name to invoke it

function brainwallet_exponent () { printf %s "$1"|sha256sum|head -c 64; }
2014-02-18 01:49:09
User: nixnax
Functions: head printf
4

A bitcoin "brainwallet" is a secret passphrase you carry in your brain.

The Bitcoin Brainwallet Exponent Calculator is one of three functions needed to calculate the bitcoin PRIVATE key. Roughly, the formula is exponent = sha256 (passphrase)

Note that this is a bash function, which means you have to type its name to invoke it.

You can check the accuracy of the results here http://brainwallet.org

server$ while true; do read -n30 ui; echo $ui |openssl enc -aes-256-cbc -a -k PaSSw; done | nc -l -p 8877 | while read so; do decoded_so=`echo "$so"| openssl enc -d -a -aes-256-cbc -k PaSSw`; echo -e "Incoming: $decoded_so"; done
2014-01-16 14:36:09
User: arno
Functions: echo read
8

client$ while true; do read -n30 ui; echo $ui |openssl enc -aes-256-cbc -a -k PaSSw ; done | nc localhost 8877 | while read so; do decoded_so=`echo "$so"| openssl enc -d -a -aes-256-cbc -k PaSSw`; echo -e "Incoming: $decoded_so"; done

This will establish a simple encrypted chat with AES-256-CBC using netcat and openssl only.

More info here http://www.nixaid.com/linux/network/encrypted-chat-with-netcat

tar --exclude-from=$excludefile -zcvp "$source" | openssl aes-128-cbc -salt -out $targetfile -k $key
2013-12-13 19:35:20
User: klausman
Functions: tar
0

Create compressed, encrypted backup from $source to $targetfile with password $key and exclude-file $excludefile

echo '#! /usr/bin/ksh\ncat $2 | openssl dgst -sha256 | read hashish; if [[ $hashish = $1 ]]; then echo $2: OK; else echo $2: FAILED; fi;' > shacheck; chmod +x shacheck; cat hashishes.sha256 | xargs -n 2 ./shacheck;
2013-09-18 21:51:20
User: RAKK
Functions: cat chmod echo read xargs
0

This command is used to verify a sha256sum-formatted file hash list on IBM AIX or any other UNIX-like OS that has openssl but doesn't have sha256sum by default. Steps:

1: Save to the filesystem a script that:

A: Receives as arguments the two parts of one line of a sha256sum listing

B: Feeds a file into openssl on SHA256 standard input hash calculation mode, and saves the result

C: Compares the calculated hash against the one received as argument

D: Outputs the result in a sha256sum-like format

2: Make the script runnable

3: Feed the sha256sum listing to xargs, running the aforementioned script and passing 2 arguments at a time

openssl aes-256-cbc -salt -in secrets.txt -out secrets.txt.enc
2013-04-13 19:33:37
User: jrdbz
1

To decrypt: openssl aes-256-cbc -d -in secrets.txt.enc -out secrets.txt.new

Reference: http://tombuntu.com/index.php/2007/12/12/simple-file-encryption-with-openssl

Optional parameter -a makes output base64 encoded, can be viewed in text editor or pasted in email

tar --create --file - --posix --gzip -- <dir> | openssl enc -e -aes256 -out <file>
2012-11-27 15:33:45
User: seb1245
Functions: tar
19

Create an AES256 encrypted and compressed tar archive.

User is prompted to enter the password.

Decrypt with:

openssl enc -d -aes256 -in <file> | tar --extract --file - --gzip
hashkey=`echo -ne <your-secret> | xxd -p`; openssl rc4 -e -nosalt -nopad -K $hashkey -in myfile.txt -out myfile.enc.txt
2012-10-31 12:17:44
User: vishnu81
Tags: openssl rc4
0

At times you will need to safeguard your files. Use OpenSSL's native rc4 encryption to do so.

'nopad' removes padding and 'nosalt' removes random salt being added to the file.

openssl rsa -in /path/to/originalkeywithpass.key -out /path/to/newkeywithnopass.key
2012-09-16 19:31:38
User: drerik
2

Strip a password from a openssl key to use with apache httpd server

ssh-keygen -l -f [pubkey] | cut -d ' ' -f 2 | tr -ds '\n:' ''
regenerateCSR () { openssl genrsa -out $2 2048; openssl x509 -x509toreq -in $1 -out $3 -signkey $2; }
touch pk.pem && chmod 600 pk.pem && openssl genrsa -out pk.pem 2048 && openssl req -new -batch -key pk.pem | openssl x509 -req -days 365 -signkey pk.pem -out cert.pem
2011-05-11 18:09:33
User: bfreis
Functions: chmod touch
1

This will create, in the current directory, a file called 'pk.pem' containing an unencrypted 2048-bit RSA private key and a file called 'cert.pem' containing a certificate signed by 'pk.pem'. The private key file will have mode 600.

!!ATTENTION!! ==> this command will overwrite both files if present.

echo -n "String to MD5" | md5sum | awk '{print $1}'
openssl base64 -d < file.txt > out
openssl dgst -sha256 <<<"test"
2010-12-05 17:34:06
User: dramaturg
Tags: openssl hash
1

No need to install yet another program when openssl is already installed. :-)

echo $(openssl rand 4 | od -DAn)
macchanger --random interface
2010-09-26 11:12:31
User: JulianTosh
Tags: sed openssl
-4

macchanger will allow you to change either 1) mfg code, 2) host id, or 3) all of the above. Use this at wifi hotspots to help reduce profiling.

openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//'
2010-09-23 02:31:12
User: putnamhill
Functions: sed
Tags: sed xxd openssl
14

Use the following variation for FreeBSD:

openssl rand 6 | xxd -p | sed 's/\(..\)/\1:/g; s/:$//'
for crt in $(locate -r '.+\.crt' | grep -v "/usr/share/ca-certificates/"); do ls -la $crt; done
2010-08-23 12:22:48
User: udog
Functions: grep locate ls
Tags: openssl locate
0

Finds all cert files on a server and lists them, finding out, which one is a symbolic link and which is true.

You want to do this when a certificate expires and you want to know which files to substitute with the new cert.

openssl base64 -in base64.decoded.txt -out base64.encoded.txt
2010-08-13 20:39:10
User: argherna
3

I have a mac, and do not want to install mac ports to get the base64 binary. Using openssl will do the trick just fine. Note, to decode base64, specify a '-d' after 'base64' in the command. Note also the files base64.decoded.txt and base64.encoded.txt are text files.

openssl x509 -in filename.crt -noout -text
openssl rand -base64 1000 | tr "[:upper:]" "[:lower:]" | tr -cd "[:alnum:]" | tr -d "lo" | cut -c 1-8 | pbcopy
2009-12-29 17:18:25
User: _eirik
Functions: cut tr
-3

eliminates "l" and "o" characters change length by changing 'x' here: cut -c 1-x

openssl des3 -salt -in unencrypted-data.tar -out encrypted-data.tar.des3
2009-10-03 03:50:46
User: berot3
3

The lifehacker way: http://lifehacker.com/software/top/geek-to-live--encrypt-your-data-178005.php#Alternate%20Method:%20OpenSSL

"That command will encrypt the unencrypted-data.tar file with the password you choose and output the result to encrypted-data.tar.des3. To unlock the encrypted file, use the following command:"

openssl des3 -d -salt -in encrypted-data.tar.des3 -out unencrypted-data.tar