Posts

Prevent Mac OSX ssh from disconnecting (also on any Linux/BSD/*nix system)

To prevent ssh from disconnecting while idle, add the following to ~/.ssh/config:

Host *
    ServerAliveInterval 30
    TCPKeepAlive no

This solution is alse useable in any Linux/BSD/*nix environment. If you want to implement this not only on your own user, as a sysadmin, add the above to /etc/ssh/ssh_config instead.

rm unable to delete file even as root or sudo [Solved]

When it is not possible to delete a file using rm even when logged in as root or by using sudo, check the file attributes with:

lsattr filename.ext

If it has the “i” attribute, this is preventing the file from being deleted, even by super users. When you have verified the reason for this and still want to delete the file then remove the “i” attribute with:

chattr -i filename.ext

Then delete the file using rm as you normally would.

/etc/cron.daily/amavisd-new: Please run this cronjob as user amavis

After a system update I started to receive cron messages saying “/etc/cron.daily/amavisd-new:
Please run this cronjob as user amavis”.

It turns out that this happens because the cron script is replaced by a new one located in /etc/cron.d and the one in /etc/cron.daily is left behind giving this error message.

Solution: After checking that the new script exists in /etc/cron.d, just delete /etc/cron.daily/amavisd-new

More information about this here (bug report).

Meltdown and Spectre vulnerabilities – what to do?

Meltdown and Spectre are two vulnerabilities present in hardware making it potentially possible for programs to steal information, like passwords etc.

Meltdown affects only Intel processors while Spectre, which is more complex, also partly affects AMD and ARM based processors.

It is not yet known if these vulnerabilities has been exploited by anone. It can affect personal computers, servers, tablets and mobile phones, i.e. more or less any device containing a processor.

More information on: https://spectreattack.com/

What can you do?

  • Check your operating system for updates the upcoming weeks (this is normal good security practice, but make sure you do it frequently)
  • Install and update your virus protection. Even if the antivirus program can’t protect you from the attack it might be able to inform you that your device has got malicious code onboard

You can find security bulletins, security advisorys, faq:s etc for your operating system here: https://meltdownattack.com/#faq-advisory

postgrey whitelisting outlook.com

Greylisting is a way of reducing the amount of incoming spam and virus emails, in addition to other counter measures. Postgrey is a good choice if you are running postfix.

However, to be able to recieve emails from senders using outlook.com you need to whitelist it. This is because outlook.com is using a different host on each try to deliver the mail, causing delays up to hours, days or the mail not being delivered at all within time limits.

Create/edit the file /etc/postgrey/whitelist_clients.local and add:

# outlook.com
/^.*\.outbound\.protection\.outlook\.com$/
/^.*\.prod\.outlook\.com$/

Then execute:

service postgrey reload

Edit December 2021: The rule is changed from /^mail-.*\.outbound\.protection\.outlook\.com$/ to /^.*\.outbound\.protection\.outlook\.com$/ as Microsoft has changed their server naming standard.

How to make a floppy file image and mounting it in Linux

To make a file image of a floppy disk in Linux (like Ubuntu), you need (of course) a computer with a floppy drive (/dev/fd0). Insert the floppy you want to copy to an image file and issue the command:

$ sudo dd bs=512 count=2880 if=/dev/fd0 of=floppy.img 

Block size (bs) and count above is for a 1,44 MB 3.5" floppy disk.

The image file can be copied back to another floppy disk with the command: 

$ sudo dd bs=512 count=2880 if=floppy.img of=/dev/fd0

The image file can also be mounted directly from the image file without the need of a physical floppy disk: 

$ sudo mkdir /media/fd
$ sudo mount -o loop floppy.img /media/fd/

I use the above method to move the content from a number of floppy disks to my hard drives. Computers today are rarely seen with a floppy drive and I wanted to secure the content before it is too late 🙂 

 

How to find out what Ubuntu version a system is running

There are two ways:

# cat /etc/issue
Ubuntu 9.10 \n \l

or

# lsb_release -a
Distributor ID:    Ubuntu
Description:    Ubuntu 9.10
Release:    9.10
Codename:    karmic

The latter is slower but gives more information.

Pimp my router! Linksys WRT54GL on steroids… or at least on Tomato

I while ago I got my hands on a Linksys WRT54GL broadband router. This little fellow runs on Linux. Nice, I thought. After fiddling around with it for a while I found that the firmware had bugs.

Linksys WRT54GLI added timed access restrictions (to cut off my teenagers Internet access automatically in the evening). This worked fine until I added another rule that had nothing to do with the first and suddenly my teenagers had Internet access all night long. I also want an incoming VPN connection (PPTP) that I forward by using port forward. This worked fine for a week and of course, it stopped working when I was abroad and needed it the most. Apart from that, there is no telnet or ssh login to the router (it is running on Linux you know).

Read more

Remove control characters (^M) by search and replace in vi

If you edit a text file in a UNIX or Linux environment that has it’s origin in the DOS or Windows world, you will see that every line ends with the control character ^M. The reason is that the UNIX or Linux world only use one control character to mark an end of line and in the DOS or Windows world this is done by two control characters.

The control characters will be automatically converted if you use ASCII mode when transferring the file by FTP between the UNIX or Linux world and the DOS or Windows world.

However, if you end up with a text file in the UNIX or Linux environment that for some reason didn’t get its end of line control characters converted, you will see that every line ends with a ^M. Those ^Ms can easily be stripped away by using the search-and-replace function in the vi editor. This requires that you have a basic knowledge on how to edit files in vi.

To search and replace the ^M you use the search and replace command %s. The format for this command is:

(press ESC key once)
:%s/TEXT/REPLACE/g

where all occurences of the TEXT will be replaced by the word REPLACE. Now we want to replace a control character, so instead of TEXT we should enter ^M. If we just type the ^ character and then the M character on our keyboard, the search and replace function will not match the ^M seen in our text file. This is because they are control characters, i.e. control-M (press and hold the CTRL-key while pressing M). If we try to just press CTRL-M after the :%s/ you will get an error message.

This is because the CTRL-M is the same as pressing the Enter key. To tell vi not to interpret the CTRL-M you need to escape it. This is done by pressing and holding CTRL in the same time as the V-character once before pressing CTRL-M. In the example below, pressing and holding CTRL while pressing the V-character is shown as a ^V and pressing and holding the the CTRL while pressing the M-character is shown as a ^M.

So to search and replace all ^M in the entire file in vi you should do:

(press ESC key once)
:%s/^V^M//g