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 password from sorted by
Terminal - Commands tagged password - 43 results
mount_smbfs '//user:p%40ss@server/share' /Volumes/share
2014-07-27 00:52:19
User: bupsy
0

If the password for the share your trying to mount contains special characters you can use URL escape characters.

The above command uses an example as follows:

username: user

password: p@ss

URL Encoded password: p%40ss

All credit goes to Richard York:

http://www.smilingsouls.net/Blog/20110526100731.html

Also check out this URL Decoder/Encoder to convert your passwords.

http://meyerweb.com/eric/tools/dencoder/

TMPFILE="/tmp/$RANDOM$RANDOM$RANDOM$RANDOM$RANDOM" && arecord -d 1 -t raw -f cd -q | base64 > $TMPFILE && pwgen -ys 12 12 -H $TMPFILE $@ && rm $TMPFILE
2014-06-09 16:28:41
User: juliohm
Functions: arecord cd rm
0

Generate a truly random password using noise from your microphone to seed the RNG. This will spit out 12 password with 12 characters each, but you can save this into a bash script and replace 'pwgen -ys 12 12' with 'pwgen $@' so you can pass any paramters to pwgen as you would normally do.

xxd -l 20 -c 20 -p /dev/urandom
2014-03-26 09:44:04
User: jt
Tags: password
0

Dumps 20 bytes from /dev/urandom and converts them to hex. -c and -p are needed to prevent splitting over lines.

echo -n "string" | md5sum|cut -f 1 -d " "
2014-02-20 22:44:00
User: labadf
Functions: cut echo
0

echo defaults to include a newline character at the end of the string, which messes with the hash. If you suppress it with -n then it has the same effect as PHP's ?echo md5("string"), "\t-";? Even more, by using cut you get the exact same output, so it works as a drop-in replacement for the original command for this thread.

cat /dev/urandom | env LC_CTYPE=C tr -dc a-zA-Z0-9 | head -c 16; echo
2014-02-05 15:04:07
User: yakovlev
Functions: cat env head tr
0

Feel free to put this in your ~/.profile:

random(){ cat /dev/urandom | env LC_CTYPE=C tr -dc $1 | head -c $2; echo; }

Then use it to generate passwords:

random [:alnum:] 16

Or DNA sequences:

random ACGT 256
SSHPASS='your_password' sshpass -e ssh me@myhost.com
2013-06-03 12:26:40
User: djkadu
Functions: ssh
0

The above is OK if you not worried about security, as per sshpass man pages:

" The -p option should be considered the least secure of all of sshpass's options. All system users can see the password in the command line with a simple "ps" command."

So, instead what I do is use the -e option:

" -e The password is taken from the environment variable "SSHPASS"."

sshpass -p "YOUR_PASSWORD" ssh -o StrictHostKeyChecking=no YOUR_USERNAME@SOME_SITE.COM
2013-05-24 14:33:38
User: o0110o
Functions: ssh
3

You need to install "sshpass" for this to work.

apt-get install sshpass

echo "ls" > script.bash; gpg -c script.bash; cat script.bash.gpg | gpg -d --no-mdc-warning | bash
2013-03-10 09:34:12
User: betsubetsu
Functions: cat echo gpg
-2

echo "ls" > script.bash;

This is my script, a simple 'ls'.

gpg -c script.bash;

Here I encrypt and passord-protect my script. This creates file script.bash.gpg.

cat script.bash.gpg | gpg -d --no-mdc-warning | bash

Here I open file script.bash.gpg, decrypt it and execute it.

wget --input-file=~/donwloads.txt --user="$USER" --password="$(gpg2 --decrypt ~/.gnupg/passwd/http-auth.gpg 2>/dev/null)"
2012-12-13 00:14:55
User: kyle0r
Functions: wget
Tags: GPG password
1

In this example, where the users gpg keyring has a password, the user will be interactively prompted for the keyring password.

If the keyring has no password, same as above, sans the prompt. Suitable for cron jobs.

~/.gnupg/passwd/http-auth.gpg is the encrypted http auth password, for this particular wget use case.

This approach has many use cases.

example bash functions:

function http_auth_pass() { gpg2 --decrypt ~/.gnupg/passwd/http-auth.gpg 2>/dev/null; }

function decrypt_pass() { gpg2 --decrypt ~/.gnupg/passwd/"$1" 2>/dev/null; }

cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 18 | head -1 | python -c "import sys,crypt; stdin=sys.stdin.readline().rstrip('\n'); print stdin;print crypt.crypt(stdin)"
2012-11-09 00:40:22
User: cnyg
Functions: cat fold head python tr
1

Generate a 18 character password from character set a-zA-Z0-9 from /dev/urandom, pipe the output to Python which prints the password on standard out and in crypt sha512 form.

echo $(</dev/urandom tr -dc 1-6 | head -c1)
echo $((0x$(head -c5 /dev/random|xxd -ps)%6+1))
2012-09-21 02:16:42
User: atoponce
Functions: echo head
9

/dev/random is said to by cryptographically secure, and unpredictable, as it gathers data from external sources, influenced by human timing interactions with computers, to fill the entropy pool. As such, this is a quick way to do a true random fair-6 dice roll. Using this method, you could easily create passphrases with Diceware http://diceware.com.

for i in {1..5}; do echo -n $((0x$(head -c5 /dev/random|xxd -ps)%6+1)); done; echo
getent passwd | cut -d: -f1 | sort
false; while [ $? != 0 ]; do apg -c /dev/urandom -n1 -E oOlL10 | egrep '^[[:alnum:]]+$'; done
while true; do curl -s http://sensiblepassword.com/?harder=1 | tail -n 15 | head -n 1 | sed 's;<br/>;;' | cut -c 5- | cb; sleep 1; done
2012-01-30 20:52:14
User: supervacuo
Functions: cut head sed sleep tail
1

Use the excellent sensiblepasswords.com to a generate random (yet easy-to-remember) password every second, and copy it to the clipboard. Useful for generating a list of passwords and pasting them into a spreadsheet.

This script uses "madebynathan"'s "cb" function (http://madebynathan.com/2011/10/04/a-nicer-way-to-use-xclip/); you could also replace "cb" with

xclip -selection c

Remove "while true; do" and "; done" to generate and copy only 1 password.

cut -d: -f1 /etc/passwd | sort
for F in *.pdf ; do qpdf --password=your_password --decrypt "$F" "$(basename $F .pdf)-nopw.pdf" ; done
2011-11-30 21:35:33
User: slc66
0

This command line will remove password from all PDF files in the current folder. It use qpdf.

read -s pass; echo $pass | md5sum | base64 | cut -c -16
2011-11-24 20:23:47
User: bugmenot
Functions: cut echo md5sum read
21

Why remember? Generate!

Up to 48 chars, works on any unix-like system (NB: BSD use md5 instead of md5sum)

slpappasswd
2011-10-13 14:46:03
User: evolix
-1

Permit to generate a password for userPassword in ldap.

Use ?slappasswd -g? to generate a random passowrd.

echo $(grep "^[^'A-Z]\{3,7\}$" /usr/share/dict/words|shuf -n4)
2011-09-07 22:03:45
User: cbbrowne
Functions: echo grep
1

This restricts things 3 ways:

1. No capitalized words, hence no proper names.

2. No apostrophes.

3. Restricts size to range (3,7)

echo $(shuf -n4 /usr/share/dict/words)
2011-08-30 03:10:06
User: bohwaz
Functions: echo
1

Some snippets posted are slow on big dictionaries, this one is fast.

pwgen 30 1
2011-07-24 19:43:48
User: sairon
6

The pwgen program generates passwords which are designed to be easily memorized by humans, while being as secure as possible. Human-memorable passwords are never going to be as secure as completely completely random passwords. [from pwgen man page]

gpg --gen-random --armor 1 30
2011-07-20 15:32:49
User: atoponce
Functions: gpg
10

According to the gpg(1) manual:

--gen-random 0|1|2 count

Emit count random bytes of the given quality level 0, 1 or 2. If count is not given or zero, an endless sequence of random bytes will be emitted. If used with --armor the output will be base64 encoded. PLEASE, don't use this command unless you know what you are doing; it may remove precious entropy from the system!

If your entropy pool is critical for various operations on your system, then using this command is not recommended to generate a secure password. With that said, regenerating entropy is as simple as:

du -s /

This is a quick way to generate a strong, base64 encoded, secure password of arbitrary length, using your entropy pool (example above shows a 30-character long password).

openssl rand -base64 12
2011-07-06 17:48:26
User: Mozai
Tags: password
3

Another password maker, for human-unfriendly passwords. '-base64' output will make sure it it can be typed on a keyboard, though the output string length will always be a multiple of 4.