ssh port forwarding without starting a new session

December 10, 2008

You can forward ports with ssh like this:

$ ssh -L 8080:localhost:80 user@remotehost

This will log you in to remotehost as user, and port 8080 on your local machine will be tunnelled to port 80 on remotehost. If remotehost can see a machine that you can’t (for example, if it’s on an internal network), you can even do this:

$ ssh -L 8080:internalhost:80 user@borderhost

This will log you in to borderhost, and localhost:8080 will be directed to internalhost:80, even though you may not be able to see internalhost directly yourself.

What I didn’t know until I read Nico Golde’s blog today, is that you can do this interactively, with an existing session. Tilde (~) is the default escape character, and ~C (note that’s an uppercase C) gets you a shell session within ssh itself:

$ ssh user@remotehost
user@remotehost$ ~C
ssh> -L 8080:localhost:80
Forwarding port.
user@remotehost$


Emptying deleted files

November 8, 2008

Mike Hommey has a nice article on clearing down deleted (but still-open) files:
http://glandium.org/blog/?p=211. He explains the problem clearly, and goes on to provide the solution, too. Well worth bookmarking, for that 2am emergency!

someone had to free some space on a 1GB filesystem, and thought a good idea would be to delete that 860MB log file that nobody cares about. Except that it didn’t really remove it, but he didn’t really check.

Later, the “filesystem full” problem came back at someone else, who came to ask me what files from a small list he could remove. But the files were pretty small, and that wouldn’t have freed enough space. That gave me the feeling that we probably were in this typical case I introduced this post with, which du -sk confirmed: 970MB used on the filesystem according to df, but only 110MB worth of data…

Mike has solutions to this for Solaris and Linux; lsof is also useful for this kind of thing, on systems which have it.


more (or less) vi

October 17, 2008

When using the more tool (this works with less, also, and less is generally more useful; you can scroll backwards and forwards with less), you can press “v” to start editing the file, in vi, at the line you are currently viewing.

This works on Linux and Solaris; please confirm on other OSes as appropriate, though I would assume that what works on more on Solaris, will work on more or less on just about any OS.

This makes using more or less far more powerful than before, and a new way into vi.


chmod syntax… be careful!

September 9, 2008

Ben Hutchings has noted a quirk in the chmod syntax: If you use the “chmod o-x” syntax, but omit the “o” (Others) (or the “u” (User) or “g” (Group)), it will default to “a” (All).

So “chmod -x foo” becomes “chmod a-x foo“; similarly, “chmod +x foo” becomes “chmod a+x foo


Bash History

September 1, 2008

Interesting list of 15 examples of bash history syntax.

Most people probably know #5:
# !ps
ps aux | grep yp

I didn’t know #13, that looks really useful for arcane purposes:
# cp ~/longname.txt /really/a/very/long/path/long-filename.txt
# ls -l !cp:2
ls -l /really/a/very/long/path/long-filename.txt


Some useful Linux / *nix admin words of experience

August 21, 2008

Entitled “Lazy Linux: 10 essential tricks for admins“, this is a pretty good set of essential commands for *nix administrators.

If I have to suggest anything for in-depth study, it’s “Trick 6″: “Remote VNC session through an SSH tunnel”, because you can actually do just about anything through an SSH tunnel. If you’re faced with you -> firewall -> internet -> remotemachine -> internet -> restoftheworld, you can do whatever you like with “restof theworld” if you can ssh to “remotemachine”, whatever the local firewall thinks. And you can probably ssh over port 443 through the firewall. Hmm; maybe I should write this up properly at some point. I’m sure it’s well documented on the web if you look for it….


Bash Quiz

June 9, 2008

Network Theory have a Bash Quiz!

Out of the ten questions, one I’m not immediately sure of without checking; another I only happened to come across earlier today, and one (echo "\'")I got wrong :-(

So, 7/10 really; 8/10 by good fortune of coming across the definition earlier today


Follow

Get every new post delivered to your Inbox.