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 using ssh from sorted by
Terminal - Commands using ssh - 284 results
sshpass -p [password] rsync -av -e ssh [utente]@[indirizzoip]:/directorydacopiare/ /directorydidestinazione
2010-01-31 15:21:14
User: 0disse0
Functions: rsync ssh
0

Check the ssh_config file and set the variable:

StrictHostKeyChecking no

ssh-keygen -T moduli-2048 -f /tmp/moduli-2048.candidates
2010-01-29 19:35:21
User: eastwind
Functions: ssh ssh-keygen
1

this command test the moduli file generated by the command ssh-keygen -G /tmp/moduli-2048.candidates -b 2048 . The test can be long depend of your cpu power , around 5 minutes to 30 minutes

ssh-keygen -G /tmp/moduli-2048.candidates -b 2048
2010-01-29 19:33:23
User: eastwind
Functions: ssh ssh-keygen
0

if you lost your moduli file in openssh server side you need generate new one with this command then test if the number generated can be used with ssh-keygen -T moduli-2048 -f /tmp/moduli-2048.candidates

seq 1 5 | parallel ssh {}.cluster.net uptime
2010-01-28 08:18:50
Functions: seq ssh
Tags: parallel
2

Parallel is from https://savannah.nongnu.org/projects/parallel/

Other examples would be:

(echo foss.org.my; echo www.debian.org; echo www.freenetproject.org) | parallel traceroute

seq -f %04g 0 9999 | parallel -X rm pict{}.jpg

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
3

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
11

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

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
23

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 HOST cat < LOCALFILE ">" REMOTEFILE
ssh root@server.com 'tshark -f "port !22" -w -' | wireshark -k -i -
2009-12-17 23:03:24
User: markdrago
Functions: ssh
26

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 -
cat ~/.ssh/id_rsa.pub | ssh <remote_host> "xargs --null echo >> ~/.ssh/authorized_keys"
2009-12-17 15:12:11
User: koushik
Functions: cat ssh
0

Well its just appending your public key to the remote hosts authorized_keys, but can get messy logging in and out

ssh -4 -C -c blowfish-cbc
2009-12-15 00:30:53
User: vxbinaca
Functions: ssh
Tags: ssh
18

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.

[ $1 == "client" ] && hostname || cat $0 | ssh $1 /bin/sh -s client
2009-11-25 22:24:31
User: a8ksh4
Functions: cat hostname ssh
6

Now put more interesting stuff on the script in replacement of hostname, even entire functions, etc, and stuff.

hosta> cat myScript.sh

#!/bin/sh

[ $1 == "client" ] && hostname || cat $0 | ssh $1 /bin/sh -s client

hosta> myScript.sh hostb

hostb

hosta>

rdp() { ssh $1 sh -c 'PATH=$PATH:/usr/local/bin; x11vnc -q -rfbauth ~/.vnc/passwd -display :0' & sleep 4; vncviewer $1:0 & }
2009-11-25 07:21:02
User: bhepple
Functions: sh sleep ssh
1

If the remote doesn't export its desktop (eg fluxbox, blackbox etc) then you need to run a x11vnc server there and a vncviewer at the local end. This command does the lot for you - it assumes that you can 'ssh' to the box without a password and that x11vnc is installed at the remote end.

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

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)

nice -n19 dump -0af - /<filesystem> -z9|gpg -e -r <gpg key id>|cstream -v 1 -t 60k|ssh <user@host> "cat > backup.img"
2009-10-29 18:27:25
User: din7
Functions: dump gpg nice ssh
2

This command will nicely dump a filesystem to STDOUT, compress it, encrypt it with the gpg key of your choice, throttle the the data stream to 60kb/s and finally use ssh to copy the contents to an image on a remote machine.

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
4

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 -g -L 8080:localhost:80 root@$HOST
2009-10-24 20:56:00
User: kayowas
Functions: ssh
-2

Forward connections to $HOSTNAME:8080 out to $HOST:80

ssh user@server 'dd if=sda.img' | dd of=/dev/sda
dd if=/dev/sda | ssh user@server 'dd of=sda.img'
ssh -R 2001:localhost:22 [username]@[remote server ip]
2009-10-11 09:51:04
User: felix001
Functions: ssh
7

Allows you to establish a tunnel (encapsulate packets) to your (Server B) remote server IP from your local host (Server A).

On Server B you can then connect to port 2001 which will forward all packets (encapsulated) to port 22 on Server A.

-- www.fir3net.com --

ssh user@host "mysqldump -h localhost -u mysqluser -pP@$$W3rD databasename | gzip -cf" | gunzip -c > database.sql
2009-10-05 00:57:51
User: daws
Functions: gunzip ssh
8

This command will dump a database on a remote stream to stdout, compress it, stream it to your local machine, decompress it and put it into a file called database.sql.You could even pipe it into mysql on your local machine to restore it immediately. I had to use this recently because the server I needed a backup from didn't have enough disk space.

ssh-keygen -R `host hostname | cut -d " " -f 4`
2009-09-23 14:58:28
User: flart
Functions: cut hostname ssh ssh-keygen
5

Quick shortcut if you know the hostname and want to save yourself one step for looking up the IP address separately.

ssh -f user@remote.ip DISPLAY=:0.0 smplayer movie.avi
2009-09-12 22:16:59
User: Escher
Functions: ssh
7

Launch a gui app remotely. In this example smplayer is installed on the remote machine, and movie.avi is in the remote user's home dir. Note that stdout/stderr is still local, so you'll have feedback locally, add '&>/dev/null' to suppress. This is surprisingly not well known (compared to running an X app locally via ssh -X). (NB. if your distro requires ~/.Xauthority file present, then try -fX if you have problems)

Resubmitted (and trimmed, thanks sitaram) due to ridiculous voting on previous submission. Fingers crossed, it gets a better rating this time.