Archive for April, 2005
LCOD – 4.25.05 – Howto get out of hung SSH sessions
Posted by Jon Zobrist in Linux, Linux Command of the Day on April 25, 2005
~.
That’s it! If you’re in a system and your modem dropped, or your DSL hung, or your connection just got lost and ssh didn’t kick you back to your prompt, just hit ~. and you’ll disconnect.
Again that’s Tilde (~) and then period (.)
If you’re in multiple systems in a chain of SSH connections this will disconnect you from the one your local machine is connected to.
LCOD – 4.14.05 – WTF is the sticky bit all about?
Posted by Jon Zobrist in Linux, Linux Command of the Day on April 14, 2005
Ok, I’ve recently wondered what exactly does the sticky bit do? I’ve set it on several things but just becuase the instructions said to. So I’ve done a little research, and there are 2 opinions floating around about what it does.. First is that it’s used to mark that a program be kept in memory once loaded, and most places citing this functionality also mention it’s mostly depricated due to speed of modern machines. The second, and correct for most modern Linux/*BSD’s is that it makes a directory have restricted group write/delete access. Basically it lets you share files in a common directory with a g+w permission but prevents users from clobbering or deleting anything but their own files.
So, how would you use this? Say you have a sales department who wants a shared directory accessible via scp (ftp is so insecure don’t use it). So you make them each an account on your server, you put them all in the sales group (edit the /etc/group file, add their usernames comma seperated after the sales group). Then you make a directory called /home/sales and
chmod +t /home/sales
chmod g+w /home/sales
chown -R root:sales /home/sales
Now you have a /home/sales dir that all members of the group sales can write to, but nobody can clobber anyone else’s files.
on Linux man chmod will give you a brief rundown of sticky
on BSD man 8 sticky will give you a more accurate description, which I’m pasting here (From FreeBSD 4.9):
NAME
sticky — sticky text and append-only directories
DESCRIPTION
A special file mode, called the sticky bit (mode S_ISVTX), is used to
indicate special treatment for directories. It is ignored for regular
files. See chmod(2) or the file /usr/include/sys/stat.h for an explana-
tion of file modes.
STICKY DIRECTORIES
A directory whose `sticky bit’ is set becomes an append-only directory,
or, more accurately, a directory in which the deletion of files is
restricted. A file in a sticky directory may only be removed or renamed
by a user if the user has write permission for the directory and the user
is the owner of the file, the owner of the directory, or the super-user.
This feature is usefully applied to directories such as /tmp which must
be publicly writable but should deny users the license to arbitrarily
delete or rename each others’ files.
Any user may create a sticky directory. See chmod(1) for details about
modifying file modes.
A Linux Dev Center article on the sticky bit
http://www.linuxdevcenter.com/pub/a/linux/lpt/22_06.html
A page that posts the (incorrect) description of the sticky bit
http://www.geocities.com/tipsforlinux/articles/028.html
A page that includes the description of Sticky along with the historical use contrasted with the modern use.
http://www.zzee.com/solutions/unix-permissions.shtml#setuid
LCOD – 4.8.05 – Getting rid of Ads/spyware with Squid proxy
Posted by Jon Zobrist in Linux, Linux Command of the Day, Uncategorized on April 8, 2005
Ok, this one is kind of a 3 step process, and I’m not going to put excessive details here about anything, I’ll link to sites that have already done that for us all!
The basic idea is to setup a squid proxy server, and have it use the hosts file that blocks lots of advertising, tracking and malware type sites. Also, I’ll post a quick howto setup a thttpd webserver with a simple page so your redirected ad sites show blank images instead of ugly 404 errors or squid cache errors.
First, setup squid on your Linux box or router. You can “emerge squid, apt-get install squid, yum install squid”, or just follow the instructions and manually install it. Now squid can be on your desktop linux box and you manually set other users on your network to connect to the web using your proxy, or squid can be set up on your linux/freebsd firewall and force users to use it, or to use iptables to do it transparently.
A good quick howto on confiruring squid is here
http://www.linuxhomenetworking.com/linux-adv/squid.htm
Note that in squid you MUST setup an acl (access control list) or you will get permission denied. You do NOT have to force squid users to put in a user/password but you can if you like, all of this is covered in that quick howto.
Next, go grab the hosts file from here
http://www.mvps.org/winhelp2002/
They update this pretty frequently, so this is something you may want to do monthly to keep the latest losers off of your network. Briefly what this is going to do is redirect all traffic to known bad people to your local box. What we’ll do is install this on your squid box, and then squid will look for a local webserver, which we’ll put up default pages & errors that make ads that get redirected look like blank spots instead of ugly errors.
So, grab the zip file, unzip it, and you’ll have a file called HOSTS, now you can use your favorite text editor (vi?) and copy everything in it to your /etc/hosts file, or you can just type cat HOSTS >> /etc/hosts
Make SURE you do 2 greater than signs (>>) and NOT 1 greater than sign (>) since that would overwrite your hosts file. Now, sometimes this gets the Windows style new lines into your /etc/hosts file, and sometimes it doesn’t, anyone know why? please post a reply with an explanation.
So now you have squid setup, and thanks to the /etc/hosts file on the squid server having lots of bad people redirected to 127.0.0.1, you’re seeing lots of http 404 errors or squid cache errors. If you’re seeing 404 errors you have a webserver running on the squid box, if you don’t want to be running a webserver and didn’t mean to install it you can probably go /etc/init.d/apache(2)? stop or /etc/init.d/httpd stop and then go find your runlevel startup dir (/etc/rc5.d or /etc/rc3.d, or on gentoo rc-update del apache2 default) and remove the link to your webserver, if you didn’t want to be running one.
Now, if you have apache/your own webserver and you don’t want to disable it you could go figure out how to setup custom 404 error pages and put up the page I’ll make below and be done. Or, if you don’t mind seeing the errors instead of ads you could be done. But I like to keep the pages I’m surfing looking good, so I run a small web server with some simple html files that are blank, here’s what you do..
First install thttpd
http://www.acme.com/software/thttpd/
or (emerge thttpd, yum install thttpd, apt-get install thttpd)
find the default directory for thttpd to serve files, grab this file and save it as index.html in that directory
http://www.submarinefund.com/lcod/files/blank.index.html
also grab this 1×1 pixel transparent gif image and put it in the same dir
http://www.submarinefund.com/lcod/files/1.gif
Now in the same directory, mkdir errors, cp index.html errors/err404.html, and cp 1.gif errors/
Fire up thttpd (/etc/init.d/thttpd start) and all your ad supported webpages should have nice blank spots all over them
You can also feel good that you’re not getting nailed with tracking cookies from big brother monitoring companies