Tanbir.NET

I am the other Tanbir Ahmed

June 17, 2013
by Tanbir A.
Comments Off

HOW TO RSYNC via SSH (Backup)

A very easy copy & paste tutorial on how to backup your very important files from your VPS, to another VPS, or linux server.

This shows to to make a secure connection between servers via SSH, so a password is no longer required between these two servers, and only those two servers to talk to each other.

Make note of your servers, (this tutorial shows how to back up one VPS, to another VPS), the main server you wish to backup, and the backup server.

Main
xxx.xxx.xxx.xxx

Backup
xxx.xxx.xxx.xxx

Follow the commands in sequence to start making backups, and changing Blue text to the appropriate user, or IP Address.

Main> ssh-keygen -t rsa -f .ssh/id_rsa

-t is the encryption type
-f tells where to store the public/private key pairs. In this case, the .ssh directory on home is being used

A password will be asked; leave this part blank, just pressing <enter>
Now, go the .ssh directory, and you will find two new files: id_dsa and id_dsa.pub. The last one is the public part. Now, copy the public key to the server machine

Main> cd .ssh
Main> scp id_rsa.pub user@Backup:~/.ssh/id_rsa.pub

Of course, this time you will need to enter the password.
Now, login into the server machine and go to the .ssh directory on the server side

Main> ssh user@Backup
Backup> cd .ssh

Now, add the client’s public key to the know public keys on the server

Backup> cat id_rsa.pub >> authorized_keys
Backup> chmod 644 authorized_keys
Backup> rm id_rsa.pub
Backup> exit

Some useful Backup commands:

  1. rsync -ravz -e “ssh” user@Main:/home /root/backup/$(date +”%d-%m-%Y”)/
  2. rsync -ravz -e “ssh” user@Main:/etc /root/backup/$(date +”%d-%m-%Y”)/
  3. rsync -ravz -e “ssh” user@Main:/var /root/backup/$(date +”%d-%m-%Y”)/
  4. rsync -ravz -e “ssh” user@Main:/var/lib/mysql /root/backup/database/$(date +”%l%p-%d-%m-%Y”)/

To make this process completely automated, crate some cron jobs for these for every hour, day, week, or month, dependent on you needs of backups.
As well as making another cron job to delete backup files older then 30 days, to keep backup space for daily backups!

find /path/to/files/* -ctime +30 -exec rm -rf {} \+

———————————————————————

Full Credit to http://codedpenguin.com

June 17, 2013
by Tanbir A.
Comments Off

SolusVM Exploit, time to look at Proxmox a bit more

Today a huge number of VPS providers got attacked with a zero day SolusVM exploit early this morning. It was bad, I mean real bad.

http://localhost.re/p/solusvm-11303-vulnerabilities

So I guess now its time to look more at Proxmox. An open-source virtualization management solution for servers. It is based on KVM and container-virtualization and manages virtual machines, storage, virtualized networks, and HA Clustering.

It means its FREE.

Try your self today: http://proxmox.com/proxmox-ve

June 15, 2013
by Tanbir A.
Comments Off

What if Superman Punched You?

So What will happen is Superman punched you?

The answer is: Superman wouldn’t just knock the wind out of you — oh, no… He would knock the atoms out of you.

For more details on this subject view this video below.

June 12, 2013
by Tanbir A.
Comments Off

RamNode has a 38% off coupon for this week only

ramnodeOne on my favorite SSD VPS provider RamNode is celebrating there one year anniversary with 38% OFF for life coupon for this week only.

USE CODE: AWESOME1

This coupon will expire in a week, so grab your RamNode VPS fast!

RamNode have been ranked in the top 4 for the last three quarters on lowendbox.com

Their VPS’s are hosted in Atlanta and Seattle. Servers are located at 55 Marietta (Atlanta) and The Westin (Seattle), they own all of their hardware and network (AS3842).

RamNode offers KVM and OpenVZ VPSs.

VPS Features

Each VPS come with the following features:

  • SolusVM control panel
  • 1Gbps fair share port speed
  • INSTANT setup
  • Weekly remote backups

For more details on the offer visit: http://lowendtalk.com/discussion/11055/ramnode-one-year-celebration-38-off-limited-time-your-favorite-ssd-vps-provider

June 6, 2013
by Tanbir A.
Comments Off

Automatically Reboot server when it runs out of memory

Reboot server on out-of-memory condition

Still, in cases where something goes awry, it is good to automatically reboot your server when it runs out of memory. This will cause a minute or two of downtime, but it’s better than languishing in the swapping state for potentially hours or days.

You can leverage a couple kernel settings and Lassie to make this happen on Linode.

Adding the following two lines to your /etc/sysctl.conf will cause it to reboot after running out of memory:

The vm.panic_on_oom=1 line enables panic on OOM; the kernel.panic=10 line tells the kernel to reboot ten seconds after panicking.

Read more about rebooting when out of memory on Linode’s wiki.

June 6, 2013
by Tanbir A.
Comments Off

Linux Advanced Security Setup

Prevent repeated login attempts with Fail2Ban

Fail2Ban is a security tool to prevent dictionary attacks. It works by monitoring important services (like SSH) and blocking IP addresses which appear to be malicious (i.e. they are failing too many login attempts because they are guessing passwords).

Install Fail2Ban:

Configure Fail2Ban:

Set “enabled” to “true” in the [ssh-ddos] section. Also, set “port” to “44444” in the [ssh] and [ssh-ddos] sections. (Change the port number to match whatever you used as your SSH port).

Save the file and restart Fail2Ban to put the new rules into effect:

Add a firewall

We’ll add an iptables firewall to the server that blocks all incoming and outgoing connections except for ones that we manually approve. This way, only the services we choose can communicate with the internet.

The firewall has no rules yet. Check it out:

Setup firewall rules in a new file:

The following firewall rules will allow HTTP (80), HTTPS (443), SSH (44444), ping, and some other ports for testing. All other ports will be blocked.

Paste the following into /etc/iptables.firewall.rules:

Activate the firewall rules now:

Verify that the rules were installed correctly:

Activate the firewall rules on startup:

Paste this into the /etc/network/if-pre-up.d/firewall file:

Set the script permissions:

Get an email anytime a user uses sudo

I like to get an email anytime someone uses sudo. This way, I have a “paper trail” of sorts, in case anything bad happens to my server. I use a Gmail filter to file these away and only look at them occasionally.

Create a new file for the sudo settings:

Add this to the file:

Set permissions on the file:

This is isn’t mentioned anywhere on the web, as far as I know, but in order for the “mail on sudo use” feature to work, you need to install an MTA server. sendmail is a good choice:

Now, you should get an email anytime someone uses sudo!

June 6, 2013
by Tanbir A.
Comments Off

Linux Basic Security Setup

Create a new user

The root user has a lot of power on your server. It has the power to read, write, and execute any file on the server. It’s not advisable to use root for day-to-day server tasks. For those tasks, use a user account with normal permissions.

Add a new user:

Add the user to the sudo group:

This allows you to perform actions that require root priveledge by simply prepending the word sudo to the command. You may need to type your password to confirm your intentions.

Login with new user:

Set up SSH keys

SSH keys allow you to login to your server without a password. For this reason, you’ll want to set this up on your primary computer (definitely not a public or shared computer!). SSH keys are very convenient and don’t make your server any less secure.

If you’ve already generated SSH keys before (maybe for your GitHub account?), then you can skip the next step.

Generate SSH keys

Generate SSH keys with the following command:

(NOTE: Be sure to run this on your local computer — not your server!)

When prompted, just accept the default locations for the keyfiles. Also, you’ll want to choose a nice, strong password for your key. If you’re on Mac, you can save the password in your keychain so you won’t have to type it in repeatedly.

Now you should have two keyfiles, one public and one private, in the ~/.ssh folder.

If you want more information about SSH keys, GitHub has a great guide.

Copy the public key to server

Now, copy your public key to the server. This tells the server that it should allow anyone with your private key to access the server. This is why we set a password on the private key earlier.

From your local machine, run:

On your Linode, run:

Disable remote root login and change the SSH port

Since all Ubuntu servers have a root user and most servers run SSH on port 22 (the default), criminals often try to guess the root password using automated attacks that try many thousands of passwords in a very short time. This is a common attack that nearly all servers will face.

We can make things substantially more difficult for automated attackers by preventing the root user from logging in over SSH and changing our SSH port to something less obvious. This will prevent the vast majority of automatic attacks.

Disable remote root login and change SSH port:

Set “Port” to “44444” and “PermitRootLogin” to “no”. Save the file and restart the SSH service:

In this example, we changed the port to 44444. So, now to connect to the server, we need to run:

Update: Someone posted this useful note about choosing an SSH port on Hacker News:

Make sure your SSH port is below 1024 (but still not 22). Reason being if your Linode is ever compromised a bad user may be able to crash sshd and run their own rogue sshd as a non root user since your original port is configured >1024. (More info here)

June 6, 2013
by Tanbir A.
Comments Off

Basic Ubuntu Setup

To set up your new server, execute the following commands.

Set the hostname

Set the server hostname. Any name will do — just make it memorable. In this example, I chose “future”.

Let’s verify that it was set correctly:

Set the fully-qualified domain name

Set the FQDN of the server by making sure the following text is in the /etc/hosts file:

It is useful if you add an A record that points from some domain you control (in this case I used “future.<your domain>.net”) to your server IP address. This way, you can easily reference the IP address of your server when you SSH into it, like so:

If you’re curious, you can read more about the /etc/hosts file.

Set the time

Set the server timezone:

Verify that the date is correct:

Update the server

Check for updates and install:

June 6, 2013
by Tanbir A.
Comments Off

LNMP – Linux, NginX, MySQL, PHP

LNMP-debianvpsStep by step LNMP installation guide for CentOS, Ubuntu, Debian

Huge thanks to http://lnmp.org/

I have compiled few sites and tested to install LNMP in my vps, and it works perfectly. The sites will give you a clear idea about LNMP and its features. These will help you a lot.

Here are the Site links for Ref:

http://www.ruchirablog.com/nginx-autoinstaller/

http://dallascao.com/en/vps-step-by-step/

 

P.S: If you are looking for cloud hosting on hourly basis, starting from $0.007/hr or $5/month, check out: https://www.digitalocean.com/ I find them very cheap.