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 - 163 results
ssh -f -N -L 5432:talk.google.com:5222 user@home.network.com
2009-06-05 23:17:21
User: dcabanis
Functions: ssh
Tags: ssh
12

If your firewall or proxy at your location prevents connection to a particular host or port, you can use ssh to tunnel to your home server and do it there instead.

ssf -f -N -L 4321:home.network.com:25 user@home.network.com
2009-06-05 23:12:02
User: dcabanis
Tags: ssh
5

Uses ssh as tunnel tunnel for an other connection.

-f runs ssh in the background -N tell that there is no command to run -L deals with the forwarding aspect where the first number is the local port number, the second is parameter is the name of the server to forward to and the third parameter is the port number on that server. The last part of the command is the usual ssh form consisting of the user name and remote server name

alias s='ssh -l root'
2009-05-07 15:57:12
User: GouNiNi
Functions: alias
-20

When you have to manage lot of servers, it's boring to type ssh root@myhost for each connection. Now you can type juste "s someting" and you are connected.

You can too add bash_completion script to complet with tab the name of your servers. This will be the next tips from me ;)

ssh user@server | tee logfilename
2009-04-17 19:17:02
User: bassu
Functions: ssh tee
6

Optionally, you can create a new function to do this with a custom command. Edit $HOME/.bashrc and add:

myssh () { ssh $1 | tee sshlog ; }

Save it.

At command prompt:

myssh user@server
diff <(ssh alice cat /etc/apt/sources.list) <(ssh bob cat /etc/apt/sources.list)
ssh -vN hostname 2>&1 | grep "remote software version"
2009-03-31 18:28:41
User: sud0er
Functions: grep hostname ssh
Tags: ssh
2

I used this to confirm an upgrade to an SSH daemon was successful

[[ $(COLUMNS=200 ps faux | awk '/grep/ {next} /ssh -N -R 4444/ {i++} END {print i}') ]] || nohup ssh -N -R 4444:localhost:22 user@relay &
2009-03-31 09:39:59
User: j0rn
Functions: awk nohup ps ssh
Tags: ssh cronjob
4

I find it ugly & sexy at the same time isn't it ?

ssh -NL 2000:remotehost:22 remotehost
ssh -fX <user>@<host> <program>
2009-03-10 15:02:35
User: prayer
Functions: ssh
Tags: ssh
15
ssh -X example.org xeyes

The SSH server configuration requires:

X11Forwarding yes # this is default in Debian

And it's convenient too:

Compression delayed

stty -echo; ssh -t HOSTNAME "sudo some_command"; stty echo
2009-03-04 19:44:36
User: jmcantrell
Functions: ssh stty
Tags: ssh sudo
3

The ssh command alone will execute the sudo command remotely, but the password will be visible in the terminal as you type it. The two stty commands disable the terminal from echoing the password back to you, which makes the remote sudo act as it does locally.

ssh -t reachable_host ssh unreachable_host
2009-03-03 23:21:36
User: patko
Functions: ssh
Tags: ssh
117

Unreachable_host is unavailable from local network, but it's available from reachable_host's network. This command creates a connection to unreachable_host through "hidden" connection to reachable_host.

zgrep "Failed password" /var/log/auth.log* | awk '{print $9}' | sort | uniq -c | sort -nr | less
2009-03-03 13:45:56
User: dbart
Functions: awk sort uniq zgrep
8

This command checks for the number of times when someone has tried to login to your server and failed. If there are a lot, then that user is being targeted on your system and you might want to make sure that user either has remote logins disabled, or has a strong password, or both. If your output has an "invalid" line, it is a summary of all logins from users that don't exist on your system.

cat /dev/tty > FILE
2009-02-25 01:43:47
User: Jo
Functions: cat
1

Takes input from the connected terminal and dumps it to the specified file. Stop writing and close file with control + D or the end of line character. Useful for copying+pasting large blobs of text over SSH to a new machine.