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 ssh from sorted by
Terminal - Commands tagged ssh - 167 results
alias sshv='ssh -vvv -o LogLevel=DEBUG3'
2010-10-30 11:23:52
User: AskApache
Functions: alias
3

When debugging an ssh connection either to optimize your settings ie compression, ciphers, or more commonly for debugging an issue connecting, this alias comes in real handy as it's not easy to remember the '-o LogLevel=DEBUG3' argument, which adds a boost of debugging info not available with -vvv alone.

Especially useful are the FD info, and the setup negotiation to create a cleaner, faster connection.

ssh root@HOST tcpdump -U -s0 -w - 'not port 22' | wireshark -k -i -
2010-10-28 09:02:39
User: abb
Functions: ssh tcpdump
10

When using tcpdump, specify -U option to prevent buffering.

ssh user@remoteserver "PGPASSWORD='passwd' pg_dump -U user bd_name | bzip2 -zv9" | bzcat | psql -U user bd_name
ssh user@host 'gunzip - > file' < file.gz
2010-09-20 14:04:47
User: putnamhill
Functions: ssh
Tags: ssh gunzip
3

This version transfers gzipped data which is unzipped as it arrives at the remote host.

lol=`zenity --file-selection --directory` && DISPLAY=:0.1 cvlc -f -I ncurses --play-and-stop "$lol"
2010-09-12 01:10:16
User: rusino
Tags: ssh vlc
0

use this command via ssh on remote machine when you want play video

remove --directory if you want select single file

lol=`zenity --entry` && DISPLAY=:0.1 cvlc -f -I ncurses --play-and-exit "$lol"
2010-09-12 01:02:53
User: rusino
Tags: ssh vlc
0

use this command via ssh on remote machine when you want play video stream or path to file

~.
2010-09-04 15:13:10
User: xeor
Tags: ssh
22

~ is the ssh control character. If you type it after a newline, you can example force close the ssh session.

, ~, then .

If you want more info, type ~? when you are connecting using ssh.

Very useful to kill of any hanging ssh sessions when nothing else works.

mussh -h host1 host2 host3 -c uptime
echo "uptime" | tee >(ssh host1) >(ssh host2) >(ssh host3)
echo "uptime" | pee "ssh host1" "ssh host2" "ssh host3"
2010-08-20 11:42:40
User: dooblem
Functions: echo
Tags: ssh parallel pee
15

The pee command is in the moreutils package.

xargs -n1 -P100 -I{} sh -c 'ssh {} uptime >output/{} 2>error/{}' <hostlist
2010-08-20 11:03:11
User: dooblem
Functions: sh uptime xargs
3

Do the same as pssh, just in shell syntax.

Put your hosts in hostlist, one per line.

Command outputs are gathered in output and error directories.

scp $user@$server:$path/to/file .
file=ftp://ftp.gimp.org/pub/gimp/v2.6/gimp-2.6.10.tar.bz2; ssh server "wget $file -O -" > $PWD/${file##*/}
2010-08-02 15:59:45
User: michaelmior
Functions: file ssh
Tags: ssh bash download
2

This command will download $file via server. I've used this when FTP was broken at the office and I needed to download some software packages.

curl -L -s `curl -s http://www.2600.com/oth-broadband.xml` | xmlstarlet sel -t -m "//enclosure[1]" -v "@url" -n | head -n 1` | ssh -t [user]@[host] "mpg123 -"
0

Ever wanted to stream your favorite podcast across the network, well now you can.

This command will parse the iTunes enabled podcast and stream the latest episode across the network through ssh encryption.

ssh [user]@[host] "ogg123 -" < [podcast].ogg
ssh [user]@[address] "mpg321 -" < [file].mp3
2010-07-30 00:23:13
User: leovailati
Functions: ssh
6

This one doesn't need to convert to wav.

sox Klaxon.mp3 -t wav - |ssh thelab@company.com paplay
2010-07-29 23:23:39
User: camocrazed
Functions: ssh
7

This will allow you to convert an audio file to wav format, and send it via ssh to a player on the other computer, which will open and play it there. Of course, substitute your information for the sound file and remote address

You do not have to use paplay on the remote end, as it is a PulseAudio thing. If the remote end uses ALSA, you should use aplay instead. If it uses OSS, you should berate them about having a lousy sound system. Also, you're not limited to transmitting encoded as wav either, it's just that AFAIK, most systems don't come with mp3 codecs, but will play wav files fine.

If you know SoX is installed on the remote end and has mp3 codecs, you can use the following instead:

cat Klaxon.mp3 |ssh thelab@company.com play -t mp3 -

this will transmit as mp3. Again, use your specific information. if you're not playing mp3s, use another type with the -t option

for host in host1 host2 host3; do ssh -n user@$host <command> > $host.log & done; wait
2010-07-14 14:55:31
User: cout
Functions: host ssh
1

Ssh to host1, host2, and host3, executing on each host and saving the output in {host}.log.

I don't have the 'parallel' command installed, otherwise it sounds interesting and less cryptic.

tsocks <program>
2010-07-11 14:16:06
User: prayer
Tags: ssh SOCKS
5

Require:

- tsocks (deb pkg)

- A working SOCKS proxy. It's easy with ssh:

$ ssh -N -D localhost:1080 your.home.pc -p 443

- tsocks configuration in your /etc/tsocks.conf (for the previous):

server = 127.0.0.1

server_port = 1080

dd if=/dev/zero bs=4096 count=1048576 | ssh user@host.tld 'cat > /dev/null'
2010-06-08 18:49:51
User: atoponce
Functions: dd ssh
Tags: ssh dd
5

The above command will send 4GB of data from one host to the next over the network, without consuming any unnecessary disk on either the client nor the host. This is a quick and dirty way to benchmark network speed without wasting any time or disk space.

Of course, change the byte size and count as necessary.

This command also doesn't rely on any extra 3rd party utilities, as dd, ssh, cat, /dev/zero and /dev/null are installed on all major Unix-like operating systems.

autossh -N -D localhost:1080 myhome.example.net -p 443
2010-05-22 19:52:30
User: prayer
Tags: ssh net
2

You may go to Internet by means of your home ssh server. You must configure your local proxy to send traffic through the proxy. Many programs allows that: firefox, pidgin, skype, gnome, etc.

Your home ssh server must listen in any of the ports permitted by your enterprise firewall. That usually includes 80 and 443.

echo 'Host or User@Host?:'; read newserver && ssh-keygen -N "" -t rsa -f ~/.ssh/id_rsa ; ssh $newserver cat <~/.ssh/id_rsa.pub ">>" ~/.ssh/authorized_keys ; ssh $newserver
2010-05-07 06:24:53
User: alf
Functions: cat echo read ssh ssh-keygen
Tags: ssh ssh-keygen
-2

Some servers don't have ssh-copy-id, this works in those cases.

It will ask for the destination server, this can be IP, hostname, or user@hostname if different from current user.

Ssh keygen will let you know if a pubkey already exists on your system and you can opt to not overwrite it.

rsync --delete -az -e 'ssh -c blowfish -i /your/.ssh/backup_key -ax' /path/to/backup remote-host:/dest/path/
ssh -o UserKnownHostsFile=/dev/null root@192.168.1.1
2010-04-08 14:55:58
User: oernii2
Functions: ssh
Tags: ssh
8

you may create an alias also, which I did ;-)

alias sshu="ssh -o UserKnownHostsFile=/dev/null "

ssh -t server 'cd /etc && $SHELL'
2010-04-02 19:34:09
User: dooblem
Functions: ssh
Tags: ssh
4

Useful to create an alias that sends you right in the directory you want :

alias server-etc="ssh -t server 'cd /etc && $SHELL'"