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.

Universal configuration monitoring and system of record for IT.

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:



May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!

Top Tags





Commands tagged ssh from sorted by
Terminal - Commands tagged ssh - 175 results
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

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


- 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 =

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

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

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

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@
2010-04-08 14:55:58
User: oernii2
Functions: ssh
Tags: ssh

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

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

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

echo 'ServerAliveInterval 60' >> /etc/ssh/ssh_config
2010-03-31 09:22:54
User: rpavlick
Functions: echo
Tags: ssh timeout

ssh_config is the system-wide configuration file for ssh.

For per-user configuration, which allows for different settings for each host:

echo 'ServerAliveInterval 60' >> ~/.ssh/ssh_config


echo 'ServerAliveInterval 60' >> ~/.ssh/config


echo 'ServerAliveInterval 60' >> ~/etc/ssh_config
ssh user@host "cat /path/to/backup/backupfile.tar.bz2" |tar jpxf -
2010-03-24 01:35:28
User: mack
Functions: ssh tar
Tags: ssh tar

Here how to recover the remote backup over ssh

tar jcpf - [sourceDirs] |ssh user@host "cat > /path/to/backup/backupfile.tar.bz2"
2010-03-24 01:29:25
User: mack
Functions: ssh tar
Tags: ssh tar

Execute it from the source host, where the source files you wish backup resides. With the minus '-' the tar command deliver the compressed output to the standar output and, trough over the ssh session to the remote host. On the other hand the backup host will be receive the stream and read it from the standar input sending it to the /path/to/backup/backupfile.tar.bz2

for I in $(mysql -e 'show databases' -u root --password=root -s --skip-column-names); do mysqldump -u root --password=root $I | gzip -c | ssh user@server.com "cat > /remote/$I.sql.gz"; done
2010-03-07 15:03:12
User: juliend2
Functions: gzip ssh

It grabs all the database names granted for the $MYSQLUSER and gzip them to a remote host via SSH.

startx -- /usr/X11R6/bin/Xnest :5 -geometry 800x600
scp -l10 pippo@serverciccio:/home/zutaniddu/* .
2010-02-19 16:44:24
User: 0disse0
Functions: scp
Tags: ssh scp bandwidth

the command is obvious, I know, but maybe not everyone knows that using the parameter "-l" you can limit the use of bandwidth command scp.

In this example fetch all files from the directory zutaniddu and I copy them locally using only 10 Kbs

file='path to file'; tar -cf - "$file" | pv -s $(du -sb "$file" | awk '{print $1}') | gzip -c | ssh -c blowfish user@host tar -zxf - -C /opt/games
2010-01-19 16:02:45
User: starchox
Functions: awk du file gzip ssh tar

You set the file/dirname transfer variable, in the end point you set the path destination, this command uses pipe view to show progress, compress the file outut and takes account to change the ssh cipher. Support dirnames with spaces.

Merged ideas and comments by http://www.commandlinefu.com/commands/view/4379/copy-working-directory-and-compress-it-on-the-fly-while-showing-progress and http://www.commandlinefu.com/commands/view/3177/move-a-lot-of-files-over-ssh

pv /dev/zero|ssh $host 'cat > /dev/null'
2010-01-06 20:40:51
User: opertinicy
Functions: ssh
Tags: ssh pv /dev/null

connects to host via ssh and displays the live transfer speed, directing all transferred data to /dev/null

needs pv installed

Debian: 'apt-get install pv'

Fedora: 'yum install pv' (may need the 'extras' repository enabled)

mkfifo /tmp/fifo; ssh-keygen; ssh-copyid root@remotehostaddress; sudo ssh root@remotehost "tshark -i eth1 -f 'not tcp port 22' -w -" > /tmp/fifo &; sudo wireshark -k -i /tmp/fifo;
sudo ssh -Y remoteuser@remotehost sudo wireshark
2010-01-05 14:35:20
User: Code_Bleu
Functions: ssh sudo

This allows you to display the wireshark program running on remote pc to your local pc.

yes | pv | ssh $host "cat > /dev/null"
2009-12-27 21:34:23
User: opertinicy
Functions: ssh yes
Tags: ssh yes pv

connects to host via ssh and displays the live transfer speed, directing all transferred data to /dev/null

needs pv installed

Debian: 'apt-get install pv'

Fedora: 'yum install pv' (may need the 'extras' repository enabled)

ssh root@server.com 'tshark -f "port !22" -w -' | wireshark -k -i -
2009-12-17 23:03:24
User: markdrago
Functions: ssh

This captures traffic on a remote machine with tshark, sends the raw pcap data over the ssh link, and displays it in wireshark. Hitting ctrl+C will stop the capture and unfortunately close your wireshark window. This can be worked-around by passing -c # to tshark to only capture a certain # of packets, or redirecting the data through a named pipe rather than piping directly from ssh to wireshark. I recommend filtering as much as you can in the tshark command to conserve bandwidth. tshark can be replaced with tcpdump thusly:

ssh root@example.com tcpdump -w - 'port !22' | wireshark -k -i -
ssh -4 -C -c blowfish-cbc
2009-12-15 00:30:53
User: vxbinaca
Functions: ssh
Tags: ssh

We force IPv4, compress the stream, specify the cypher stream to be Blowfish. I suppose you could use aes256-ctr as well for cypher spec. I'm of course leaving out things like master control sessions and such as that may not be available on your shell although that would speed things up as well.

ssh <host> 'tar -cz /<folder>/<subfolder>' | tar -xvz
2009-11-10 20:06:47
User: polaco
Functions: ssh tar

This command will copy a folder tree (keeping the parent folders) through ssh. It will:

- compress the data

- stream the compressed data through ssh

- decompress the data on the local folder

This command will take no additional space on the host machine (no need to create compressed tar files, transfer it and then delete it on the host).

There is some situations (like mirroring a remote machine) where you simply cant wait for a huge time taking scp command or cant compress the data to a tarball on the host because of file system space limitation, so this command can do the job quite well.

This command performs very well mainly when a lot of data is involved in the process. If you copying a low amount of data, use scp instead (easier to type)

ssh-keygen -l -f /etc/ssh/ssh_host_rsa_key.pub && ssh-keygen -l -f /etc/ssh/ssh_host_dsa_key.pub
2009-10-26 17:52:41
Functions: ssh ssh-keygen
Tags: ssh bash

Get your server's fingerprints to give to users to verify when they ssh in. Publickey locations may vary by distro. Fingerprints should be provided out-of-band.

ssh user@machine_A dd if=/dev/dvd0 > dvddump.iso
2009-09-11 18:08:36
User: kamathln
Functions: dd ssh
Tags: ssh dvd dump

You can use this to directly dump from machine A (with dvd drive) to machine B (without dvd drive) . I used this to copy dvd using my friend's machine to my netbook. Above command is to be issued on machine B.

Advantages :

1) No wasting time dumping first to machine A and then copying to Machine B.

2) You dont need to use space on Machine A. In fact, this will work even when Machine A doesnt have enough hdd space to dump the DVD.

Use -C ssh option on slow networks (enables compression).

you can replace "dd if=/dev/dvd" with any ripping command as long as it spews the iso to stdout.