I came up with two new bash aliases tonight. Enjoy.
alias lld='ls -alFd `find * .* -maxdepth 0 -type d`' alias lsd='ls -d `find * -maxdepth 0 -type d`'
I came up with two new bash aliases tonight. Enjoy.
alias lld='ls -alFd `find * .* -maxdepth 0 -type d`' alias lsd='ls -d `find * -maxdepth 0 -type d`'
I was wondering how I could disable the console screen saver on my server (so I can watch progress of stuff in the background) and I found this article, How do I permanently disable Linux’s console screen saver, system-wide?
One of the solutions suggests installing the console-tools package, but there is another solution that looks like it doesn’t need any package installed, so I’m gonna give that a try first. The solution is to edit /etc/kbd/config and specify:
BLANK_TIME=0 POWERDOWN_TIME=0
I’ve configured that now but won’t be able to test for a while as I can’t reboot my server just at the moment.
While I was at it I figured I’d have num lock enabled by default too:
LEDS=+num
Update: I was finally able to reboot my system and test that config, and: it didn’t work.
I tried to apt-get install console-tools, but that make things even worse! I recommend that you don’t try and install console-tools on Ubuntu Lucid, if my experience is anything to go by. Lucky I could still SSH to my server, because there was no console!
In the end I settled on a solution I found over here, being to add the following to /etc/rc.local:
setterm -blank 0 -powersave off -powerdown 0
I wanted to do something about the fact that I get a lot of spam where the date is substantially in the past, that is, months or years ago.
I figure I’ll never get any mail that I care about where the date is set that far back so what I wanted was a way to filter out such email.
There didn’t seem to be any suitable option in Thunderbird, and I’d rather have this done on the server than the client anyway, so I started fishing around for options in Postfix.
I found out about header checks.
To enable I had to add a file to the header_checks configuration option in /etc/postfix/main.cf:
header_checks = regexp:/etc/postfix/header_filter_map regexp:/etc/postfix/spamheadercheck
Then I created a header_filter_map file with some regexes for the date:
/^Date: .* [JFMASOND][aepuco][nbrynlgptvc] 1\d\d\d/ DISCARD Date 1 /^Date: .* [JFMASOND][aepuco][nbrynlgptvc] 200\d/ DISCARD Date 2 /^Date: .* [JFMASOND][aepuco][nbrynlgptvc] 201[0-1]/ DISCARD Date 3 /^Date: .* Jan 2012/ DISCARD Date Jan /^Date: .* Feb 2011/ DISCARD Date Feb /^Date: .* Mar 2011/ DISCARD Date Mar /^Date: .* Apr 2011/ DISCARD Date Apr /^Date: .* May 2011/ DISCARD Date May /^Date: .* Jun 2011/ DISCARD Date Jun /^Date: .* Jul 2011/ DISCARD Date Jul /^Date: .* Aug 2011/ DISCARD Date Aug /^Date: .* Sep 2011/ DISCARD Date Sep /^Date: .* Oct 2011/ DISCARD Date Oct /^Date: .* Nov 2011/ DISCARD Date Nov /^Date: .* Dec 2011/ DISCARD Date Dec
I also found this file so I added some rules for the X-Mailer header, like this:
/^X-Mailer: 0001/ DISCARD Mailer 1 /^X-Mailer: Avalanche/ DISCARD Mailer 2 /^X-Mailer: Crescent Internet Tool/ DISCARD Mailer 3 /^X-Mailer: DiffondiCool/ DISCARD Mailer 4 /^X-Mailer: E-Mail Delivery Agent/ DISCARD Mailer 5 /^X-Mailer: Emailer Platinum/ DISCARD Mailer 6 /^X-Mailer: Entity/ DISCARD Mailer 7 /^X-Mailer: Extractor/ DISCARD Mailer 8 /^X-Mailer: Floodgate/ DISCARD Mailer 9 /^X-Mailer: GOTO Software Sarbacane/ DISCARD Mailer 10 /^X-Mailer: MailWorkz/ DISCARD Mailer 11 /^X-Mailer: MassE-Mail/ DISCARD Mailer 12 /^X-Mailer: MaxBulk.Mailer/ DISCARD Mailer 13 /^X-Mailer: News Breaker Pro/ DISCARD Mailer 14 /^X-Mailer: SmartMailer/ DISCARD Mailer 15 /^X-Mailer: StormPort/ DISCARD Mailer 16 /^X-Mailer: SuperMail-2/ DISCARD Mailer 17
Now that I know how to do this I’ll start adding rules for particular spam that I seem to get a lot of.
I’m not sure if I made the best decision, but I decided to silently discard email rather than reject it.
I had some messages from my fail2ban log like this:
2012-02-03 00:59:33,810 fail2ban.actions.action: ERROR iptables -N fail2ban-apache 2012-02-03 00:59:33,838 fail2ban.actions.action: ERROR iptables -N fail2ban-apache-overflows 2012-02-03 03:42:49,355 fail2ban.actions.action: ERROR iptables -D INPUT -p tcp -m multiport --dports http,https -j fail2ban-apache-overflows 2012-02-03 03:43:04,998 fail2ban.actions.action: ERROR iptables -N fail2ban-ssh-ddos 2012-02-03 03:43:05,035 fail2ban.actions.action: ERROR iptables -N fail2ban-apache-overflows 2012-02-03 07:13:04,720 fail2ban.actions.action: ERROR iptables -D INPUT -p tcp -m multiport --dports http,https -j fail2ban-apache-overflows 2012-02-03 07:13:20,154 fail2ban.actions.action: ERROR iptables -N fail2ban-ssh-ddos
I read over here about a workaround that goes like this:
Edit /usr/bin/fail2ban-client and add a call to time.sleep to mitigate a race condition:
def __processCmd(self, cmd, showRet = True):
beautifier = Beautifier()
for c in cmd:
time.sleep(0.1)
beautifier.setInputCmd(c)
In my .vimrc file I set expandtab, which means tab characters are converted to spaces.
Today I had to edit a python file, and I know python is funny about tabs and spaces, so I wanted to temporarily disable the expandtab feature in Vim.
Turns out you can do it with:
:set expandtab!
Today I learned that you can get a status report from fail2ban by running:
$ sudo fail2ban-client status
Read a good article on Samba and IPTables today.
To disable a user login:
$ sudo passwd -l username
To unlock a disabled user login:
$ sudo passwd -u username
To specify all the secondary groups a user should be in (if they’re already in a group not in this list they will be removed from it) you use:
$ sudo usermod -G grp_a,grp_b username
To append to the list of secondary groups:
$ sudo usermod -a -G grp_c username
To show what users are in a group:
$ grep ^group: /etc/group
E.g. to show which users are in the sudo group:
$ grep ^sudo: /etc/group
You also need to check primary groups by grepping for the gid in the passwd file. For instance the gid for the sudo group is 27, so to see who’s in sudo you also have to:
$ grep 27 /etc/passwd
Of course you should take all of the above with a grain of salt because there are a thousand caveats.
I was reading about Postfix’s cleanup facility which supports header_checks which can be specified in a regexp: table. And it inspired me to come up with this header_filter_map file:
/^Date: .* [JFMASOND][aepuco][nbrynlgptvc] 1/ REJECT /^Date: .* [JFMASOND][aepuco][nbrynlgptvc] 200/ REJECT /^Date: .* [JFMASOND][aepuco][nbrynlgptvc] 2010/ REJECT /^Date: .* [JFMASOND][aepuco][nbrynlgptvc] 2011/ REJECT /^Date: .* Jan 2012/ REJECT /^Date: .* Feb 2011/ REJECT /^Date: .* Mar 2011/ REJECT /^Date: .* Apr 2011/ REJECT /^Date: .* May 2011/ REJECT /^Date: .* Jun 2011/ REJECT /^Date: .* Jul 2011/ REJECT /^Date: .* Aug 2011/ REJECT /^Date: .* Sep 2011/ REJECT /^Date: .* Oct 2011/ REJECT /^Date: .* Nov 2011/ REJECT /^Date: .* Dec 2011/ REJECT
Which I applied in Postfix by adding the following line to /etc/postfix/main.cf:
header_checks = regexp:/etc/postfix/header_filter_map
It remains to be seen if what I’ve done will work, and at the moment this is a bit of a pain because I have to manually update the header_filter_map file every month, but the general idea is that if the regexp matches a date too far in the past then the message is rejected. Hopefully then those spammers who have messages turning up in my history will be gone.
I had a problem with my rsync backups. The problem was that the first time I ran it everything worked fine. The second time it ran (and all subsequent times) I got back the phone book of error messages, because the first time I’d run rsync it had copied in a whole heap of read-only files, and then when I ran it again it wasn’t able to overwrite those read-only files. At least I think that was what was happening. So I added the following to my backup script:
find . -type d -exec chmod u+x {} \;
if [ "$?" -ne "0" ]; then
echo "Cannot chmod directories in '$PWD'.";
exit 1;
fi
find . -type f -exec chmod u+rw {} \;
if [ "$?" -ne "0" ]; then
echo "Cannot chmod files in '$PWD'.";
exit 1;
fi
This code runs after rsync and processes the files and directories that have been synchronised. That is, it processes the copy of the data, not the data I copied from.
For the copy of the data I want to make sure that the owner of the files can read and write them and that the owner of the directories can execute them. So that’s what the above code does.