Archive for category Linux

IPsec VPN Server Auto Setup Scripts

First, prepare your Linux server* with a fresh install of Ubuntu LTS, Debian or CentOS.

Use this one-liner to set up an IPsec VPN server:

wget https://git.io/vpnsetup -O vpnsetup.sh && sudo sh vpnsetup.sh
If using CentOS, replace the link above with https://git.io/vpnsetup-centos.

Your VPN login details will be randomly generated, and displayed on the screen when finished.

For other installation options and how to set up VPN clients, read the sections below.

* A dedicated server or virtual private server (VPS). OpenVZ VPS is not supported.

https://github.com/hwdsl2/setup-ipsec-vpn

,

No Comments

Installing and running shadowsocks on Ubuntu Server

Shadowsocks-libev is a lightweight secured SOCKS5 proxy for embedded devices and low-end boxes.

It is a port of Shadowsocks created by @clowwindy, and maintained by @madeye and @linusyang.

==========================================================
Install the the shadowsocks-libev package from apt repository.

sudo apt update
sudo apt install shadowsocks-libev
Save ss.json as /etc/shadowsocks-libev/config.json.

Replace server_port and password in ss.json with your own choices.

Restart the shadowsocks-libev service.

sudo systemctl restart shadowsocks-libev
sudo systemctl status shadowsocks-libev

No Comments

Apache server 2.4.6 hangs after serving requests from Internet Explorer 10/11

Apache server 2.4.6 hangs after serving requests from Internet Explorer 10/11

Symptoms:
Apache 2.4 running on Windows hangs when Internet Explorer 10/11 is used to acces pages on it.

 

Reproduction:

I had a very reproducible scenario: Only the first request to Apache coming from IE would work, all other subsequent requests would hang, in all browsers. As long as I did not use Internet Explorer there did not seem to be a problem, but once that was used everything would hang until Apache was restarted. Strangely enough after I had applied the fix (see below) I reverted it to do some more testing but was not able to reproduce the problem anymore…

 

Migitating factors:
I am not sure of these, just describing the setup I was using when I encountered these problems. If you know more, please leave a comment.

  • Running on Windows 7
  • Using Apache 2.4.6
  • VMWare network drivers installed (see explanation for why this might be relevant)
  • Using an experimental 64-bit build of PHP 5.5: php-5.5.5-Win32-VC11-x64
  • Using Internet Explorer 11
  • Using Twitter Bootstrap, MySQL

Cause:
It seems that I was being hit by an issue with Apache’s Multi-Processing Module optimized for Windows NT. See references below for some sources that describe this problem and the fix.

Fix:
Add this configuration snippet to Apache24/conf/httpd.conf (bottom of file seems fine):

# Apparently this fixes an issue with Apache 2.4.6 on Windows hanging
# when serving requests from Internet Explorer 10/11.
AcceptFilter http none
AcceptFilter https none

Explanation:
From the Apache docs about AcceptFilter:

This directive enables operating system specific optimizations for a listening socket by the Protocol type.

On Windows, none uses accept() rather than AcceptEx() and will not recycle sockets between connections. This is useful for network adapters with broken driver support, as well as some virtual network providers such as vpn drivers, or spam, virus or spyware filters.

Copied from site: http://stijndewitt.wordpress.com/2014/01/10/apache-hangs-ie11/

No Comments

Migrate MySQL Setting to New Server

oldserver$ mysqldump mysql > mysql.sql

newserver$ mysql mysql < mysql.sql

newserver$ mysql ‘flush privileges;’

No Comments

Delete Files Older Than x Days on Linux

find * -mtime +5 -exec rm {} \;

Note that there are spaces between rm, {}, and \;

Explanation

  • The first argument is the path to the files. This can be a path, a directory, or a wildcard as in the example above. I would recommend using the full path, and make sure that you run the command without the exec rm to make sure you are getting the right results.
  • The second argument, -mtime, is used to specify the number of days old that the file is. If you enter +5, it will find files older than 5 days.
  • The third argument, -exec, allows you to pass in a command such as rm. The {} \; at the end is required to end the command.

This should work on Ubuntu, Suse, Redhat, or pretty much any version of linux.

Ref: http://www.howtogeek.com/howto/ubuntu/delete-files-older-than-x-days-on-linux/

 

No Comments

How to set a static IP in Ubuntu from the shell

Edit /etc/network/interfaces


# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# This is a list of hotpluggable network interfaces.
# They will be activated automatically by the hotplug subsystem.
mapping hotplug
        script grep
        map eth0

# The primary network interface
auto eth0
iface eth0 inet static
        address 192.168.0.100
        netmask 255.255.255.0
        network 192.168.0.0
        broadcast 192.168.0.255
        gateway 192.168.0.1

No Comments

Ubuntu VNC Config (/home/user/.vnc/xstartup)

#!/bin/sh

# Uncomment the following two lines for normal desktop:
unset SESSION_MANAGER
#exec /etc/X11/xinit/xinitrc

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources

xsetroot -solid grey
vncconfig -iconic &
xterm -geometry 80×24+10+10 -ls -title “$VNCDESKTOP Desktop” &

gnome-session &

No Comments

Configuring SSL in Tomcat

Configuring SSL in Tomcat

No Comments

OpenVPN Installation

Server Side Installation and Key Generation

1. Install OpenVPN referencing this guide :
openvpn-how-to

2. Install NEWEST RC Client OpenVPN 2.1_rc18
(Only this version support Vista 64 bits!!!)

3. Get the keys from server (supposing is using secure way, but… I just use insecure way for demo)

  • in /etc/openvpn
  • . ./vars
  • build-key username
  • the keys are stored in $KEY_DIR (usually the /etc/openvpn/keys)

Configure Client

4.Configure the client configuration

– copy ca.crt, client.crt, client.key to C:\Program Files (x86)\OpenVPN\config

5. Copy C:\Program Files (x86)\OpenVPN\sample-config\client.ovpn (in windows, client.conf if using Linux) to C:\Program Files (x86)\OpenVPN\config

– Edit the port, ca.crt, client.crt, client.key configuration values

6. Install OpenVPN GUI ( I assume that you want to use GUI)

– http://openvpn.se/files/binary/openvpn-gui-1.0.3.exe

6. run!

** To redirect all traffic to VPN Server

1. Add following line in server.conf

push “redirect-gateway def1”

2. Run “echo 1 > /proc/sys/net/ipv4/ip_forward” in server (thanks wallace)

3. iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE

4. Add following line in client.conf (client.ovpn in Windows)

push “dhcp-option DNS 10.8.0.1”

* Remarks: HKBN DNS Server: 203.186.94.20

No Comments

How to create a self-signed SSL Certificate …

Overview

The following is an extremely simplified view of how SSL is implemented and what part the certificate plays in the entire process.

Normal web traffic is sent unencrypted over the Internet. That is, anyone with access to the right tools can snoop all of that traffic. Obviously, this can lead to problems, especially where security and privacy is necessary, such as in credit card data and bank transactions. The Secure Socket Layer is used to encrypt the data stream between the web server and the web client (the browser).

SSL makes use of what is known as asymmetric cryptography, commonly referred to as public key cryptography (PKI). With public key cryptography, two keys are created, one public, one private. Anything encrypted with either key can only be decrypted with its corresponding key. Thus if a message or data stream were encrypted with the server’s private key, it can be decrypted only using its corresponding public key, ensuring that the data only could have come from the server.

If SSL utilizes public key cryptography to encrypt the data stream traveling over the Internet, why is a certificate necessary? The technical answer to that question is that a certificate is not really necessarythe data is secure and cannot easily be decrypted by a third party. However, certificates do serve a crucial role in the communication process. The certificate, signed by a trusted Certificate Authority (CA), ensures that the certificate holder is really who he claims to be. Without a trusted signed certificate, your data may be encrypted, however, the party you are communicating with may not be whom you think. Without certificates, impersonation attacks would be much more common.

Step 1: Generate a Private Key

The openssl toolkit is used to generate an RSA Private Key and CSR (Certificate Signing Request). It can also be used to generate self-signed certificates which can be used for testing purposes or internal usage.

The first step is to create your RSA Private Key. This key is a 1024 bit RSA key which is encrypted using Triple-DES and stored in a PEM format so that it is readable as ASCII text.

openssl genrsa -des3 -out server.key 1024

Generating RSA private key, 1024 bit long modulus
…………………………………………………++++++
……..++++++
e is 65537 (0x10001)
Enter PEM pass phrase:
Verifying password – Enter PEM pass phrase:

Step 2: Generate a CSR (Certificate Signing Request)

Once the private key is generated a Certificate Signing Request can be generated. The CSR is then used in one of two ways. Ideally, the CSR will be sent to a Certificate Authority, such as Thawte or Verisign who will verify the identity of the requestor and issue a signed certificate. The second option is to self-sign the CSR, which will be demonstrated in the next section.

During the generation of the CSR, you will be prompted for several pieces of information. These are the X.509 attributes of the certificate. One of the prompts will be for “Common Name (e.g., YOUR name)”. It is important that this field be filled in with the fully qualified domain name of the server to be protected by SSL. If the website to be protected will be https://public.akadia.com, then enter public.akadia.com at this prompt. The command to generate the CSR is as follows:

openssl req -new -key server.key -out server.csr

Country Name (2 letter code) [GB]:CH
State or Province Name (full name) [Berkshire]:Bern
Locality Name (eg, city) [Newbury]:Oberdiessbach
Organization Name (eg, company) [My Company Ltd]:Akadia AG
Organizational Unit Name (eg, section) []:Information Technology
Common Name (eg, your name or your server’s hostname) []:public.akadia.com
Email Address []:martin dot zahn at akadia dot ch
Please enter the following ‘extra’ attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

Step 3: Remove Passphrase from Key

One unfortunate side-effect of the pass-phrased private key is that Apache will ask for the pass-phrase each time the web server is started. Obviously this is not necessarily convenient as someone will not always be around to type in the pass-phrase, such as after a reboot or crash. mod_ssl includes the ability to use an external program in place of the built-in pass-phrase dialog, however, this is not necessarily the most secure option either. It is possible to remove the Triple-DES encryption from the key, thereby no longer needing to type in a pass-phrase. If the private key is no longer encrypted, it is critical that this file only be readable by the root user! If your system is ever compromised and a third party obtains your unencrypted private key, the corresponding certificate will need to be revoked. With that being said, use the following command to remove the pass-phrase from the key:

cp server.key server.key.org
openssl rsa -in server.key.org -out server.key

The newly created server.key file has no more passphrase in it.

-rw-r–r– 1 root root 745 Jun 29 12:19 server.csr
-rw-r–r– 1 root root 891 Jun 29 13:22 server.key
-rw-r–r– 1 root root 963 Jun 29 13:22 server.key.org

Step 4: Generating a Self-Signed Certificate

At this point you will need to generate a self-signed certificate because you either don’t plan on having your certificate signed by a CA, or you wish to test your new SSL implementation while the CA is signing your certificate. This temporary certificate will generate an error in the client browser to the effect that the signing certificate authority is unknown and not trusted.

To generate a temporary certificate which is good for 365 days, issue the following command:

openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
Signature ok
subject=/C=CH/ST=Bern/L=Oberdiessbach/O=Akadia AG/OU=Information
Technology/CN=public.akadia.com/Email=martin dot zahn at akadia dot ch
Getting Private key

Step 5: Installing the Private Key and Certificate

When Apache with mod_ssl is installed, it creates several directories in the Apache config directory. The location of this directory will differ depending on how Apache was compiled.

cp server.crt /usr/local/apache/conf/ssl.crt
cp server.key /usr/local/apache/conf/ssl.key

Step 6: Configuring SSL Enabled Virtual Hosts

SSLEngine on
SSLCertificateFile /usr/local/apache/conf/ssl.crt/server.crt
SSLCertificateKeyFile /usr/local/apache/conf/ssl.key/server.key
SetEnvIf User-Agent “.*MSIE.*” nokeepalive ssl-unclean-shutdown
CustomLog logs/ssl_request_log \
“%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \”%r\” %b”

Step 7: Restart Apache and Test

/etc/init.d/httpd stop
/etc/init.d/httpd stop

https://public.akadia.com

,

No Comments