Installing UFW – Uncomplicated Firewall on Ubuntu 12.04

If you are one of those nerdy types and use iptables, ignore this. If you are like the rest of us Ubuntu users (nerdy in denial), UFW (Uncomplicated Firewall) provides a handy tool to configure your firewall.

Here’s how to install. As root, type:

apt-get install ufw

If this can’t find the package, run

apt-get update

before running the command again. You’ll get it.

Next, add your exceptions. For example, on my server, I allow ssh (Secure Shell) and http (Hypertext Transfer Protocol).

# ufw allow ssh
# ufw allow http

Then start the firewall

# ufw enable

It will ask

Command may disrupt existing ssh connections. Proceed with operation (y|n)?

Reply “y”. Simply hitting enter will abort.

This should return:

Firewall is active and enabled on system startup

If you get an error like

ERROR: problem running ufw-init

Edit the file /etc/default/ufw and change IPv6=yes to IPv6=no

Enhanced by Zemanta

Need to install jpegtran?

If you are optimizing your blog/site, you may end up needing a package for optimizing images called jpegtran It is a part of another package called 

libjpeg-progs

To install, simply install the package, like so

apt-get install libjpeg-progs
Done.

Need to install jpegtran?

If you are optimizing your blog/site, you may end up needing a package for optimizing images called jpegtran It is a part of another package called 

libjpeg-progs

To install, simply install the package, like so

apt-get install libjpeg-progs
Done.

How to create an admin area on fake domain

Often, you need to have areas of your site that you access through a browser, that you don’t want anyone else to access. These can be control panels or scripts with phpinfo or your apc cache monitoring script.

what I do is create a fake domain for these and give them their own site. For example a virtual host for domain “admin.area” which of course is not a real domain name or registered anywhere. Remove the index file, forbid browsing folders and place your scripts there.

Plug in your server IP address with the fake domain you created (admin.area) into the hosts file of any computer that needs access.

If you are using varnish, you can also redirect any queries to this domain to your main website for safety and access through the backend port.

You can easily disable the virtual domain altogether when done without interfering with your production sites in any way and risking accidental permission changes or other problems.

Phpize: Command not found?

So you are on Debian, trying perhaps to install an opcode cache or something and you use try to do it with pecl with


pecl install apc

for example.

And you can’t, because phpize is not installed. Then you try to compile it and run into the same problem.

Then you try to find out how to get it, only to need a package “php5-devel” that doesn’t seem to exist in any repository.

Fikar not. What you want is “php5-dev” – strange that this seems to not be mentioned in most instructions.

So you go.


apt-get install php5-dev

then you have phpize for whatever you were trying to do.

🙂

How to forward only .onion or .i2p urls selectively

If you are like me and don’t need to use TOR so much for anonymity as for accessing interesting hidden sites, the overall slow speed of TOR probably bothers you for normal browsing. The need to toggle proxies or start two separate browsers probably bugs you too.

Now I have found .i2p which is similar to TOR in the sense of being an anonymous, decentralized network, but it is not a proxy at all – which means configuring the browser to forward queries via the i2p network means that regular sites won’t work at all!

I need:

  • Normal browsing directly over the internet for regular urls
  • Routing .onion urls to TOR
  • Routing .i2p urls to I2P

I dare say this fix will also work for any other such networks I may not know of.

Before we begin, an extremely important WARNING:

If you use TOR for Anonymity, then this “how to” may compromise your anonymity for the same reasons the TORbutton was discontinued. Mixing normal browsing with TOR may result in leaks of identity or inadvertent access of normal urls which you intend to use over TOR directly – which could be disastrous, particularly if your safety depends on it. YOU ARE WARNED. This “How To” ASSUMES THAT YOU DO NOT HAVE ANONYMITY AS A PRIORITY.

There are many people who would simply like to see various sites, or have TOR sites they interact with regularly – like TORMail users, for example. Or people who have set up their own sites or are reading forums or otherwise engaged in activity that they don’t think will be legally problematic.

This guide is for them. And I hope their tribe increases.

Here’s how to see normal urls directly on the internet, while using TOR and I2P for .onion and .i2p sites respectively.

Step 1: Install Privoxy. Privoxy is a transparent proxy that does a lot of other useful things too. Visit their website, read up, and if you like (and want to continue this how to) install privoxy as per instructions for your OS. This assumes that you already have I2P and/or TOR installed – or you can go now and do it, or waste your time reading this post. I use TOR installed from the PPA and not the browser bundle – so that it can run in the background and be used as needed – or stopped independently of the browser if I’m not using TOR. This is important, as I browse all day, and having the browser shut down if I’m not using TOR would be most inconvenient. Wasting bandwidth on TOR unnecessarily is not required either.

Step 2: Configure your browser to use Privoxy – as per instructions given on their site. Basically, this means setting your network proxy to 127.0.0.1:8118 <– this is the port for Privoxy. Note DO NOT add the socks proxy for TOR here. Or the i2p settings.

Step 3: Edit your Privoxy configuration file. On Ubuntu, installing from the PPA it is found at /etc/privoxy/config – your mileage may vary depending on OS and how you installed privoxy, however, it will be found in the root of the folder for privoxy – as a rough guide.

Step 4: At the end of that file, add:

forward-socks5   .onion               127.0.0.1:9050 .
forward   .i2p               127.0.0.1:4444 .

Done.

That is it.

Now, your normal browsing will be unaffected by either TOR or I2P Network, while .onion and .i2p urls will get forwarded correctly and accessible seamlessly.

Enjoy!

NOTE: While this does nothing special to compromise your safety, it may be compromising some protective feature in case someone is trying to find out your identity or something. I have no clue what it does on the safety front, and I highly recommending assuming that this is unsafe till some superior being can verify or suggest better methods.

If, while using this method, you find that you need to use anonymous features of TOR, I highly recommend starting a “TOR Browser Bundle” browser separately. This can be configured to use different ports so as to not interfere with your already installed TOR.

NOTE1: I know I am being repetitive, but I feel I must, seeing as how a lot of people use TOR for activism or other things where getting identity compromised could land them in a lot of trouble.

Install APC and fix “potential cache slam” problem

APC is an Alternative PHP Cache or Opcode cache that speeds up performance dramatically by caching queries.

How to install APC?

apt-get install php5-apc

You will have to enble it in the php configuration. Add the following to your php.ini file

extension=apc.so

Alternatively, you could create a separate apc.ini file and put it in the conf.d directory.

If your error log shows a lot of messages about potential cache slam averted, it is a bug. Not much you can do about it but you can turn slam defense off so that it doesn’t spam your logs (or cause other fails)

Add after that line in your php.ini or apc.ini

apc.write_lock = 1
apc.slam_defense = 0

How to install APC and fix “potential cache slam” problem

APC is an Alternative PHP Cache or Opcode cache that speeds up performance dramatically by caching queries.

How to install APC?

apt-get install php5-apc

or

pecl install apc

You will have to enble it in the php configuration. Add the following to your php.ini file

extension=apc.so

Alternatively, you could create a separate apc.ini file and put it in the conf.d directory.

If your error log shows a lot of messages about potential cache slam averted, it is a bug. Not much you can do about it but you can turn slam defense off so that it doesn’t spam your logs (or cause other fails)

Add after that line in your php.ini or apc.ini

apc.write_lock = 1
apc.slam_defense = 0

Then copy the apc.php file into a folder that is served by your webserver. Accessing this script in a browser gives you information on the state of your cache. However this script also allows viewing of the files cached and may be a security concern, so it is best kept in a folder with restricted access.

WordPress: Problem happened with plugin upgrade – can’t delete old files

When you get an error like this while updating, check file ownership. Chances are that you edited something in the backend and the plugin or theme files now being owned by another user, cannot be deleted by the server.

If you have terminal access as root, type:

chown -R www-data:www-data /path/to/wordpress/*

Where www-data is the user your Apache runs as and /path/to/wordpress is of course the path to the root of your wordpress installation. the “*” is to apply to all files and folders and the “-R” earlier means the command [chown – for change owner – in this case] applies recursively to all files and folders contained in the folder named.

If you try to upgrade now, it should work.

Varnish won’t start – Too many arguments (…)

So you set up Varnish. You really did everything right, but when you try to start it…

root@www:/etc/apache2/sites-available# service varnish start
* Starting HTTP accelerator varnishd [fail]
SMA.s0: max size 512 MB.
Too many arguments (...)
usage: varnishd [options] -a …

and so on, and you have tried and tried to edit /etc/default/varnish till you’re ready to give up?

Varnish works fine if you start it from the command line with configuration (as described in the documentation – for testing), but fails to start as a daemon?

The problem is some invalid characters related with line break in the /etc/default/varnish file. They seem to be there in the original file itself. I was not able to fix the characters, but simply editing the file so that the whole configuration appears as one line works.

So, for example:

DAEMON_OPTS="-a :80
-T localhost:1234
-f /etc/varnish/default.vcl
-s malloc,256m"

Becomes

DAEMON_OPTS="-a :80 -T localhost:1234 -f /etc/varnish/default.vcl -s malloc,256m"

This worked for me. If you don’t like this you could try fixing whatever the issue is with the linebreak. Do tell me if you figure it out.