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 - 287 results
cat .ssh/id_dsa.pub | ssh <HOST> "mkdir -p .ssh && tee -a .ssh/authorized_keys"
ssh login@server "cat path/filename.mp3" | mplayer -
sshpass -p 'sshpssword' ssh -t <sshuser>@<remotehost> "echo <sudopassword> | sudo -S <command>"
2012-09-13 20:27:13
User: dynaguy
Functions: ssh
Tags: ssh sudo sshpass
2

Example: remote install an application(wine).

sshpass -p 'mypssword' ssh -t mysshloginname@192.168.1.22 "echo 'mypassword' | sudo -S apt-get install wine"

Tested on Ubuntu.

s() { screen -d -RR -m -S "$1" -t "$USER"@"$1" ssh "$1"; }
2012-09-07 23:02:52
User: salamando
Functions: screen ssh
Tags: ssh screen Linux
5

Use as: $ s host1

Will ssh to remote host upon first invocation. Then use C-a d to detatch. Running "s host1" again will resume the shell session on the remote host. Only useful in LAN environment. You'd want to start the screen on the remote host over a WAN.

Adapted from Hack 34 in Linux Server Hacks 2nd Addition.

sudo ssh -D 88 -fN user@xxxx.no-ip.info
ssh -l username server.tdl "tar -czf - /home/username/public_html" | tar -xzf -
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 user@host $(< /dev/fd/0)
2012-07-18 10:36:07
User: trantorvega
Functions: echo ssh
2

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 tester@10.2.6.10 "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 tester@10.2.6.10 "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 root@192.168.0.1 "dd of=/dest/folder/file.tar.gz"
2012-07-13 17:54:51
User: kruspemsv
Functions: ssh tar
1

You can ran this also with cat for example:

tar zcvf - /folder/ | ssh root@192.168.0.1 "cat > /dest/folder/file.tar.gz"

Or even run other command's:

tcpdump | ssh root@10.0.0.1 "cat > /tmp/tcpdump.log"
ssh-copy-id -i .ssh/id_rsa.pub user@server
cat .ssh/id_rsa.pub | ssh user@server 'cat >> ~/.ssh/authorized_keys2'
2012-07-12 15:42:10
User: er0k
Functions: cat ssh
-4

for passwordless login

ssh user@hostname.domain "> ~/.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 user@localhost will be registered in the history as well, and it's not usable.

rsync -avz -e ssh user@host:/srcpath destpath
ssh -v jsmith@remotehost.example.com
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 user@host cat /path/to/remotefile) /path/to/localfile
ssh user@host "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
0

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 user@host "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 username@host
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 user@localhost 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 user@remote "cat /path/to/archive.tgz" | tar zxvf -
xloadimage <(ssh USER@HOSTNAME 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 't@uyM59bQ' ssh username@server.example.com
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 user@somedomain.org
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 user@localhost -p 8888