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.


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

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!
Hide

Top Tags

Hide

Functions

Psst. Open beta.

Wow, didn't really expect you to read this far down. The latest iteration of the site is in open beta. It's a gentle open beta-- not in prime-time just yet. It's being hosted over at UpGuard (link) and you are more than welcome to give it a shot. Couple things:

  • » The open beta is running a copy of the database that will not carry over to the final version. Don't post anything you don't mind losing.
  • » If you wish to use your user account, you will probably need to reset your password.
Your feedback is appreciated via the form on the beta page. Thanks! -Jon & CLFU Team

Commands using ssh from sorted by
Terminal - Commands using ssh - 304 results
ssh-keygen -l -f [pubkey] | cut -d ' ' -f 2 | tr -ds '\n:' ''
ssh-copy-id host
2012-07-24 08:43:41
Functions: ssh
0

If the username on the remote host is the same as on the local machine you can omit the username.

echo "properly_escaped_command" | ssh [email protected] $(< /dev/fd/0)
2012-07-18 10:36:07
User: trantorvega
Functions: echo ssh
1

It executes commands as arguments to ssh, avoiding problematic shell expansions, without the need of writing the commands in question to a temporary file, just reading them from STDIN.

cat ~/.ssh/id_rsa.pub | ssh [email protected] "mkdir -p ~/.ssh; cat >> ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys"
2012-07-18 04:41:55
Functions: cat ssh
0

chmod authorized_keys so you don't get "Authentication refused: bad ownership or modes for file /home/user/.ssh/authorized_keys"

cat ~/.ssh/id_rsa.pub | ssh [email protected] "mkdir -p ~/.ssh; cat >> ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys"
2012-07-18 04:41:54
Functions: cat ssh
0

chmod authorized_keys so you don't get "Authentication refused: bad ownership or modes for file /home/user/.ssh/authorized_keys"

tar cvzf - /folder/ | ssh [email protected] "dd of=/dest/folder/file.tar.gz"
2012-07-13 17:54:51
User: kruspemsv
Functions: ssh tar
1

Really useful when out of space in your current machine.

You can ran this also with cat for example:

tar zcvf - /folder/ | ssh [email protected] "cat > /dest/folder/file.tar.gz"

Or even run other command's:

tcpdump | ssh [email protected] "cat > /tmp/tcpdump.log"
cat .ssh/id_rsa.pub | ssh [email protected] 'cat >> ~/.ssh/authorized_keys2'
2012-07-12 15:42:10
User: er0k
Functions: cat ssh
-4

for passwordless login

ssh [email protected] "> ~/.bash_history"
2012-07-09 14:29:22
User: maxadamo
Functions: ssh
1

Only from a remote machine:

Only access to the server will be logged, but not the command.

The same way, you can run any command without loggin it to history.

ssh [email protected] will be registered in the history as well, and it's not usable.

rsync -avz -e ssh [email protected]:/srcpath destpath
ssh -v [email protected]
2012-06-26 16:11:35
User: ankush108
Functions: ssh
Tags: ssh debug
0

Sometimes it is necessary to view debug messages to troubleshoot any

SSH connection issues. pass -v (lowercase v) option to the ssh as shown

below to view the ssh debug messages.

diff <(ssh [email protected] cat /path/to/remotefile) /path/to/localfile
ssh [email protected] "ffmpeg -f x11grab -r 5 -s 1280x720 -i :0 -f avi -" | ffplay - &>/dev/null
2012-05-01 06:26:49
User: buhrietoe
Functions: ssh
Tags: ssh ffmpeg ffplay
1

Play with the framerate option '-r' to scale back bandwidth usage.

The '-s' option is the captured screan area, not the rescaled size. If you want to rescale add a second '-s' option after '-i :0'. Rescaling smaller will also decrease bandwidth.

ssh [email protected] "ffmpeg -f x11grab -s 1920x1080 -i :0 -r 1 -t 1 -f mjpeg -" | display
2012-05-01 04:45:15
User: buhrietoe
Functions: ssh
0

More stealthy ffmpeg method. The imagemagick 'import' method causes a system beep.

ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no [email protected]
2012-04-20 01:54:04
User: dmmst19
Functions: ssh
10

This command will bypass checking the host key of the target server against the local known_hosts file.

When you SSH to a server whose host key does not match the one stored in your local machine's known_hosts file, you'll get a error like " WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!" that indicates a key mismatch. If you know the key has legitimately changed (like the server was reinstalled), a permanent solution is to remove the stored key for that server in known_hosts.

However, there are some occasions where you may not want to make the permanent change. For example, you've done some port-forwarding trickery with ssh -R or ssh -L, and are doing ssh [email protected] to connect over the port-forwarding to some other machine (not actually your localhost). Since this is usually temporary, you probably don't want to change the known_hosts file. This command is useful for those situations.

Credit: Command found at http://linuxcommando.blogspot.com/2008/10/how-to-disable-ssh-host-key-checking.html. Further discussion of how it works is there also.

Note this is a bit different than command #5307 - with that one you will still be prompted to store the unrecognized key, whereas this one won't prompt you for the key at all.

ssh [email protected] "cat /path/to/archive.tgz" | tar zxvf -
xloadimage <(ssh [email protected] DISPLAY=:0.0 import -window root png:-)
2012-03-02 23:01:44
User: brejktru
Functions: ssh
10

standard image viewers do not seem to be able to open a FIFO file. xloadimage was the first one i've stumbled upon that can handle this.

sshpass -p [email protected]' ssh [email protected]
2012-02-13 09:51:41
User: djyoda
Functions: ssh
-1

You can use sshpass command to provide password for ssh based login. sshpass is a utility designed for running ssh using the mode referred to as "keyboard-interactive" password authentication, but in non-interactive mode.

ssh -f -N -R 8888:localhost:22 [email protected]
2012-02-08 20:24:38
User: 0disse0
Functions: ssh
Tags: ssh
5

this command from the source server and this follow in the destination server:

ssh [email protected] -p 8888

diff -y <(ssh [email protected] find /boot|sort) <(find /boot|sort)
2012-01-31 15:04:30
User: knoppix5
Functions: diff find ssh
3

You can compare directories on two different remote hosts as well:

diff -y <(ssh [email protected] find /boot|sort) <(ssh [email protected] find /boot|sort)

To avoid password-prompt on remote host just generate the rsa key locally and copy it to remote host:

ssh-keygen -t rsa

then

ssh [email protected] "mkdir .ssh"

then

scp .ssh/id_rsa.pub [email protected]:; .ssh/authorized_keys2
ssh [email protected] sudo tcpdump -i eth0 -w - 'port 80'| /Applications/Wireshark.app/Contents/Resources/bin/wireshark -k -i -
ssh-keygen -R $(dig +short host.domain.tld)
2012-01-19 15:08:50
User: atoponce
Functions: dig ssh ssh-keygen
2

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

ssh-keygen -R <thehost>
ssh 10.0.0.4 "gzip -c /tmp/backup.sql" |gunzip > backup.sql
2012-01-06 17:44:06
User: ultips
Functions: gunzip ssh
0

If you have servers on Wide Area Network (WAN), you may experience very long transfer rates due to limited bandwidth and latency.

To speed up you transfers you need to compress the data so you will have less to transfer.

So the solution is to use a compression tools like gzip or bzip or compress before and after the data transfer.

Using ssh "-C" option is not compatible with every ssh version (ssh2 for instance).

ssh [email protected] "rpm -qa" | xargs yum -y install
ssh [email protected] "tar -zcf - /path/to/dir" > dir.tar.gz
2011-12-16 05:48:38
User: __
Functions: ssh
Tags: ssh tar gzip
20

This improves on #9892 by compressing the directory on the remote machine so that the amount of data transferred over the network is much smaller. The command uses ssh(1) to get to a remote host, uses tar(1) to archive and compress a remote directory, prints the result to STDOUT, which is written to a local file. In other words, we are archiving and compressing a remote directory to our local box.