Showing posts with label Ubuntu. Show all posts
Showing posts with label Ubuntu. Show all posts

Friday, September 26, 2014

How to permenently Add DNS entry in Ubuntu 12.04

Just open the following file 
sudo nano /etc/resolvconf/resolv.conf.d/head
and add entries as follows:
nameserver <your DNS IP>
i.e. 
nameserver 192.168.10.1
 
Source http://ubuntuforums.org/showthread.php?t=2078398 

Saturday, March 1, 2014

Mac OS X: Wake Up Servers Using Wake-on-LAN ( WOL ) Command Utility

know how to send WOL command using Linux or FreeBSD wake command. But, how do I send Wake on LAN (WOL) frames to hosts on a local Ethernet network using Apple OS X operating systems to wake up my servers or nas devices?


You need to use wakeonlan Perl script that generates and transmits a Wake-On-LAN (WOL) "Magic Packet", used for restarting machines that have been soft powered-down (ACPI D3-warm state).


Download wakeonlan

Open a terminal and type the following curl command:
$ cd /tmp
$ curl http://gsd.di.uminho.pt/jpo/software/wakeonlan/downloads/wakeonlan-0.41.tar.gz -o out.tag.gz
Untar the tar ball with the help of tar command, enter:
$ tar xvf out.tag.gz
Sample outputs:

x wakeonlan-0.41/
x wakeonlan-0.41/README
x wakeonlan-0.41/Makefile.PL
x wakeonlan-0.41/META.yml
x wakeonlan-0.41/SIGNATURE
x wakeonlan-0.41/Changes
x wakeonlan-0.41/MANIFEST
x wakeonlan-0.41/examples/
x wakeonlan-0.41/examples/lab001.wol
x wakeonlan-0.41/wakeonlan

Install Perl script

Type the following mkdir command:
$ mkdir ~/bin/

Copy /tmp/wakeonlan-0.41/wakeonlan to ~/bin/ directory with the cp command:
$ cp /tmp/wakeonlan-0.41/wakeonlan ~/bin/

How do I send WOL on OS X?

The syntax is:
$ ~/bin/wakeonlan server-mac-address-here

For example, if nas01 server has 00:08:9b:c4:30:30 mac address, enter:
$ ~/bin/wakeonlan 00:08:9b:c4:30:30
Sample outputs:
Sending magic packet to 255.255.255.255:9 with 00:08:9b:c4:30:30

Other options
    -i ip_address
        set the destination IP address
        default: 255.255.255.255 (the limited broadcast address)
    -p port
        set the destination port
        default: 9 (the discard port)
    -f file
        uses file as a source of hardware addresses

Apple computer wake for network access (WOL) setting

If you want other users to be able to access your Apple OS X based computer’s shared resources, such as shared printers/files/folders or iTunes playlists, even when your computer is in sleep mode. Open System Preferences > choose "Energy Saver preferences". This set options that control your computer’s energy use including WOL for all Mac Based server and client systems:

Make sure you select the option "Wake for network access" so that other users can wake up your computer using WOL magic packet.

Sunday, July 7, 2013

How to Disable GUI Boot in Ubuntu 12.04

Following the steps I followed to enable console boot in Ubuntu 12.04
Step 1 First update your repository by running
sudo apt-get update
Step 2 There is some bug in old version of lightdm, so we need to upgrade the same. To do so run,
sudo apt-get install lightdm
Step 3 Now we have to modify grub config.
Step 3a Open /etc/default/grub with your faviourite editor and change
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
to
GRUB_CMDLINE_LINUX_DEFAULT="text"
Step 3b Also comment GRUB_HIDDEN_TIMEOUT=0 This line is for unhiding the GRUB menu

Step 4 Now we will upgrade GRUB configuration
sudo update-grub
Step 5 Now restart your machine. Voilla you will be in console mode
At any time you need after booting your system you want to change to gui mode the run
startx
If you want to restore Ubuntu’s GUI mode then

Open /etc/default/grub with your faviourite editor and change
GRUB_CMDLINE_LINUX_DEFAULT="text"
to
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
Update GRUB by running
sudo update-grub
That’s it

Tuesday, June 18, 2013

How to Set Up SSH Keys

About SSH Keys


SSH keys provide a more secure way of logging into a virtual private server with SSH than using a password alone. While a password can eventually be cracked with a brute force attack, SSH keys are nearly impossible to decipher by brute force alone. Generating a key pair provides you with two long string of characters: a public and a private key. You can place the public key on any server, and then unlock it by connecting to it with a client that already has the private key. When the two match up, the system unlocks without the need for a password. You can increase security even more by protecting the private key with a passphrase.

Step One—Create the RSA Key Pair


The first step is to create the key pair on the client machine (there is a good chance that this will just be your computer):
ssh-keygen -t rsa

Step Two—Store the Keys and Passphrase


Once you have entered the Gen Key command, you will get a few more questions:
Enter file in which to save the key (/demo/.ssh/id_rsa):

You can press enter here, saving the file to the user home (in this case, my example user is called demo).
Enter passphrase (empty for no passphrase):

It's up to you whether you want to use a passphrase.

Entering a passphrase does have its benefits: the security of a key, no matter how encrypted, still depends on the fact that it is not visible to anyone else. Should a passphrase-protected private key fall into an unauthorized users possession, they will be unable to log in to its associated accounts until they figure out the passphrase, buying the hacked user some extra time. The only downside, of course, to having a passphrase, is then having to type it in each time you use the Key Pair.

The entire key generation process looks like this:
ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/demo/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /demo/.ssh/id_rsa.
Your public key has been saved in /demo/.ssh/id_rsa.pub.
The key fingerprint is:
4a:dd:0a:c6:35:4e:3f:ed:27:38:8c:74:44:4d:93:67 demo@a
The key's randomart image is:
+--[ RSA 2048]----+
|          .oo.   |
|         .  o.E  |
|        + .  o   |
|     . = = .     |
|      = S = .    |
|     o + = +     |
|      . o + o .  |
|           . o   |
|                 |
+-----------------+

The public key is now located in /demo/.ssh/id_rsa.pub

The private key (identification) is now located in /demo/.ssh/id_rsa

Step Three—Copy the Public Key


Once the key pair is generated, it's time to place the public key on the virtual server that we want to use.

You can copy the public key into the new machine's authorized_keys file with the ssh-copy-id command. Make sure to replace the example username and IP address below.
ssh-copy-id user@123.45.56.78

Alternatively, you can paste in the keys using SSH:
cat .ssh/id_rsa.pub | ssh user@123.45.56.78 "cat >> ~/.ssh/authorized_keys"

No matter which command you chose, you should see something like:
The authenticity of host '12.34.56.78 (12.34.56.78)' can't be established.
RSA key fingerprint is b1:2d:33:67:ce:35:4d:5f:f3:a8:cd:c0:c4:48:86:12.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '12.34.56.78' (RSA) to the list of known hosts.
user@12.34.56.78's password: 
Now try logging into the machine, with "ssh 'user@12.34.56.78'", and check in:

  ~/.ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

Now you can go ahead and log into user@12.34.56.78 and you will not be prompted for a password. However, if you set a passphrase, you will be asked to enter the passphrase at that time (and whenever else you log in in the future).

Optional Step Four—Disable the Password for Root Login

Once you have copied your SSH keys unto your server and ensured that you can log in with the SSH keys alone, you can go ahead and restrict the root login to only be permitted via SSH keys.

In order to do this, open up the SSH config file:
sudo nano /etc/ssh/sshd_config

Within that file, find the line that includes PermitRootLogin and modify it to ensure that users can only connect with their SSH key:
PermitRootLogin without-password

Put the changes into effect:
reload ssh
 
 
Source: 
https://www.digitalocean.com/community/articles/how-to-set-up-ssh-keys--2 

Tuesday, April 2, 2013

Import a large MySQL database over SSH

By default, most PHP uploaders limit the import file size of a MySQL database to 50MB. You may not always be able to change the limit yourself (depending upon your host) so the alternative way to import the database is to use SSH.

Start by uploading the .sql file onto the server using your regular FTP/FTPS/SFTP client.
Log into the server using SSH and navigate to the directory where your .sql file is.
Run this command:
mysql -p -u username database_name < file.sql
Notes:
The -p will prompt for your database password.
Replace username, database and file.sql with their appropriate values.
--------------------------------------------------------------------------------

If you are accessing via cPanel root use following command :
root $: cd /home
root $: ls
root $: cd /home/username of domain


Friday, March 29, 2013

Move Virtual Box Virtual Machines to New Server/Location

Step 1: Locate and move the Virtual Machine
You will be looking for a .vdi file. The location of this file will depend upon the host platform. On Linux host, the file will be found in ~/VirtualBox VMs.

On Mac Host, the file will be found in Go>Home>VirtualBox VMs

Within that directory, you will find sub-directories of all your virtual machines. Within the virtual machine directory in question, you will find the .vdi file — that is, the file that must be moved to the new host. Copy that file to an external or shared drive and then copy it onto the new host (the location doesn’t matter).


Step 2: Create a new virtual machine
The process of creating the new virtual machine will be the same as if you were creating a standard virtual machine until you get to the Virtual Hard Disk creation screen (Figure-1). You will select Use Existing Hard Disk, click the folder icon, navigate to the newly copied .vdi file, select the file in question, and then click Next.



Step 3: Copy All MAC addressess
When you move your VM to new location it is good to copy your network card MAC address from Old Virtual Box and past into new Virtual Box virtual machine, For doing this you will not face any complicated network connectivity issue after starting your machine.

Follow the step below:

1..Select newly created Virtual machine in virtual box.
2..Click on setting
3..Click on Network
4..Delete existing MAC address and Past the same mac address as it was in old Virtual Box VM.
5..Do it with all network Cards.
6..Also make same setting for network like "NAT or Bridge" etc.


------------------------------------------------------------------------------------------------------


Since your mac address have changed you no longer have an interface called eth0, this name is reserved for an interface with the "old" mac-address. The "new" interface should have the next free name (eg. ethN).


To see all the interfaces on the machine you can use this command:

ifconfig -a

If you want to reset the name reservations for network interfaces you can remove the file

/etc/udev/rules.d/70-persistent-net.rules

and restart the machine (or remove/insert the device, though this is not possible in this case).

Alternatively you can change the interface-name that you have configured to what ever the new one is called by changing all occurences of the old name with the new one in the file


/etc/network/interfaces

Friday, March 22, 2013

HOW TO SHARE EXTERNAL HARD DRIVE FROM MAC OS X TO LINUX UBUNTU

IN MAC
---------
To Enable file sharing:
-----------------------
1..From the Apple drop-down list, select System Preferences....
2..Click the Sharing icon.
3..In Mac OS X select 10.4 select the Services tab.
4..Check on "File Sharing" and "Remote Log in"
5..When finished, close the Sharing window.

To check Username (administrator) of External Drive
----------------------------------------------------
1..Right Click on External Exp drive
2..Click on Get info
3..Click Under the Sharing and Permission
(Note supper username for this External hard drive that is usually your admin and password)


IN UBUNTU
--------------
1..$sudo apt-get install sshfs
2..Go to Places and click "Connect to Server"
3..From the "Type" select ssh
4..in the Server put IP of your remote server
5..in the user detail put username and password of the remote server
6..Click connect
7..Done

NOW YOU CAN BROWS/COPY/PAST THE WHOLE REMOTE COMPUTER AND ITS DRIVES AS YOU CAN IN UBUNTU.

Monday, January 28, 2013

Setting up FTP for your website Ubuntu 12.04

File Transfer Protocol (FTP) is a standard network protocol used to transfer files from one host to another over a TCP-based network, such as the Internet. Its most common use is uploading your website files to your webserver, allowing you to develop your website, upload it via FTP then refresh the page to see the updated page. If you’re setting up your own webservers its essential you have some way of uploading files and the best way to do this is with FTP. First you need to setup and configure an ftp server on your webserver, in this tutorial we are going to be using ProFTP. ProFTPD is a proven, high-performance and scalable FTP server, with a focus toward simplicity, security, and ease of configuration.


I’ve gone through many FTP server tutorials in the past and they all work fine for uploading to your home directory but in this situation we don’t want to just upload to our home directors, we want to upload to our website directors, in this case /var/wwwr. First off we need to setup a new user for our ftp login details:

sudo useradd [username]
sudo passwd [username]


Now we need to add the www-data group so it can write to you webserver storage, be warned this will set the users primary group to www-data so ensure you have created a new user especially for use as an ftp account.
sudo usermod  -g www-data [username]

Now in most situations your website is stored in /var/www, this often restricts writing from the www-data group so we need to change the permissions to allow any user in the www-data group to write to the /var/www folder:

sudo chmod -R g+w /var/www

Now we are ready to actually install the server, simply type:
sudo apt-get install proftpd
and select the Stand Alone option when asked.

Now we need to make some small configuration changes to ProFTP, first open then proftpd.conf file:
sudo nano /etc/proftpd/proftpd.conf

and edit the following lines to match my example,
# Use this to jail all users in their homes
DefaultRoot                     /var/www
# Set the user and group that the server normally runs at.
User                            www-data
Group                           www-data

Now we need to restart ProFTP so that it recognises the new settings:
sudo /etc/init.d/proftpd restart

and thats it your ftp server should be setup to allow you to upload, edit and download your website, to test this simply type in:
ftp 127.0.0.1

and enter your login details, now try making a folder with the following command
mkdir test

if you can do this with no errors that your ftp server has been correctly configured.


 Trouble shooting
-----------------
1.. if you face permission problem during upload problem use following command
  chown -R www-data:www-data /var/www

2... Use passive mode in file zilla and/or dreamweaver


Wednesday, January 4, 2012

Create your own Dynamic DNS Service using PowerDNS and MySQL

Dynamic DNS services can be very useful for sites or servers with dynamic IP addresses. Most residential Internet providers will only provide you with a dynamic IP address, making it quite difficult to manage systems remotely. This problem can be remedied with the use of Dynamic DNS where a software client updates the DNS server with the latest IP address of the site. Many providers already exist which provide this service such as No-IP.com or DyDNS.com. These are good, but unfortunately not all of their features are free and they require you to log in every once in a while to make sure that your account doesn’t get deactivated. In this article, I’m going to show you how you can setup your own Dynamic DNS service using PowerDNS and MySQL to update your dynamic sites’ IP in your own DNS server.


Instructions

These instructions assume that you have a domain name (purchased from a provider such as GoDaddy or otherwise) and you have the ability to point your domain to your own name servers.




Step 1

Install PowerDNS and its dependencies for MySQL.

Ubuntu / Debian

sudo apt-get install pdns-server pdns-backend-mysql mysql-server

CentOS / RHEL / Fedora


yum install pdns pdns-backend-mysql mysql-server



Step 2

Configure PowerDNS with your MySQL details.

sudo nano /etc/powerdns/pdns.d/pdns.local

# Here come the local changes the user made, like configuration of
# the several backends that exist.

gmysql-host=127.0.0.1
gmysql-user=<mysql user>
gmysql-password=<mysql password>
gmysql-dbname=<powerdns database>



Step 3 (Optional)

You can optionally install a web frontend to manage your domains. I recommend PowerDNS Administrator.
http://code.google.com/p/pdnsadministrator/downloads/list



Step 4

Configure the update script to update the DNS record in the database.

sudo mkdir -p /opt/dynamic-dns

sudo nano /opt/dynamic-dns/update.php

<?php

$ip = $argv[1];
$domain = $argv[2];


// Make MySQL Connection
mysql_connect("localhost", "powerdns", "a4031b869c") or die(mysql_error());
mysql_select_db("powerdns") or die(mysql_error());

// Update record in database.
$result = mysql_query("UPDATE records SET content='$ip' WHERE name='$domain' and type='A';")

?>


Step 5

Install openssh-server and openssh-client in both servers.

sudo apt-get install openssh-server
sudo apt-get install openssh-client

Configure SSH Keys on the dynamic host for passwordless authentication to the DNS server. Be sure to change the <user> and <powerdns ip>
to the correct values.

ssh-keygen (Accept all the default values.)

cat ~/.ssh/id_rsa.pub | ssh username@hostname 'cat >> .ssh/authorized_keys'



Step 6

Configure the client script/cron job to fetch the dynamic host’s current IP address and update the DNS database. Be sure to update the bold values with the appropriate values.

sudo nano /etc/cron.hourly/dynamic-dns.cron && sudo chmod +x /etc/cron.hourly/dynamic-dns.cron

#!/bin/bash
IP=`curl -s http://www.whatismyip.org`
DOMAIN=<dynamic dns domain>
ssh -C <user>@<powerdns ip> php /opt/dynamic-dns/update.php $IP $DOMAIN
echo “`date` $DOMAIN – Updated IP to $IP” >> /var/log/dynamic-dns.log

Wednesday, November 23, 2011

How To Install and configure Varnish Cache in ubuntu

Install & Configure Varnish on Ubuntu Lucid Linux

I decided to install Varnish on an Ubuntu 10.04 Lucid Linux machine.
1. Install Varnish
2. Edit the /etc/varnish/default.vcl file
3. Edit the /etc/default/varnish file
4. Edit apache settings
5. Restart Apache and Varnish
6. Useful commands and information

1. Install Varnish

sudo apt-get install varnish

2. Edit the /etc/varnish/default.vcl file

This is where we tell varnish where to find content. I want varnish to find content on the local machine on port 8080, or basically where to find the webserver. By default apache listens on port 80 so we will need to change the apache settings later on. Edit the /etc/varnish/default.vcl file and change the contents as shown.


backend default {
.host = "127.0.0.1";
.port = "8080";
}

3. Edit the /etc/default/varnish file

This file contains varnish’s startup settings. The default set up is mostly fine. The main thing here is to tell varnish which port to listen on and how much RAM it can use. I want varnish to listen on port 80 and use 128M of RAM.



DAEMON_OPTS="-a :80 \
-T localhost:6082 \
-f /etc/varnish/default.vcl \
-S /etc/varnish/secret \
-s file,/var/lib/varnish/$INSTANCE/varnish_storage.bin,128M"

4. Edit apache settings

You must edit /etc/apache/ports.conf file and ensure apache will now listen on port 8080. If you have a vhosts setup you must also change which port the vhosts listen on.

So /etc/apache/ports.conf should look like this


NameVirtualHost *:8080
Listen 8080
.....

Change /etc/apache2/sites-available/default to also listen on port 8080, and do the same for any vhosts in this directory.


NameVirtualHost *:8080
Listen 8080
.....

Example vhosts



ServerName mormanski.net
.....

5. Restart Apache and Varnish

Restart apache.
sudo /etc/init.d/apache2 restart
And start Varnish too.
sudo /etc/init.d/varnish start

6. Useful commands and information

This netstat command will tell you which ports are open
netstat -anp --tcp --udp | grep LISTEN

You can use varnishlog to see what’s happening in real time
varnishlog

Tuesday, June 28, 2011

How to connect mysql database from joomla web server on local network

SITUATION

you have 2 Server one is joomla web server(192.168.1.52) and 2nd is database server (192.168.1.51)

Now you want to connect your joomla webserver to database server.Install Ubuntu server 10.10 in both server and also install LAMP with openSSH server with Client.
Connect with same local area network.

Step -1 (in database server)

configure mysql configuration file by typing following command:

sudo nano /etc/mysql/my.cnf

Make sure line skip-networking is commented (or remove line) and add following line

bind-address=192.168.1.51 (YOUR-DATABASE SERVER-IP)

now save and Close the file then reboot the server

Step-2 (In database server)

Grant access to a new database

Connect mysql localy by typing following command

mysql -u root -p mysql

If you want to add a new database called shah for user joomla and remote IP 192.168.1.52 then you need to type the following commands at mysql> prompt:

mysql> CREATE DATABASE shah;
mysql> GRANT ALL ON shah.* TO joomla@'192.168.1.52' IDENTIFIED BY 'PASSWORD';

How Do I Grant Access To An Existing Database?Let us assume that you are always making connection from joomla web server IP called 192.168.1.52 for database called shah for user joomla, To grant access to this IP address type the following command At mysql> prompt for existing database, enter:

mysql> update db set Host='192.168.1.52' where Db='shah';
mysql> update user set Host='192.168.1.52' where user='joomla';


Type exit command to logout mysql:

mysql> exit

you can also do this by phpmyadmin

just use following setting while making new database in phpmyadmin

user name = joomla (you can use your own name)
password = password (you can use your own)
host = any host (you can also put here your joomla webserver static ip so only your web server will be able to access in your local net)
Priveliges = check all (check all and Grant all Access)

Step-3 (In joomla web server)

Test your database connecting properly.

mysql -u joomla –h 192.168.1.51 –p


Where,
-u joomla: joomla is MySQL username
-h IP or hostname: 192.168.1.51 is MySQL server IP address or hostname (FQDN)
-p : Prompt for password

Step-4 (In Joomla web server)

You can now install joomla into your joomla web server (192.168.1.52)
and put database server ip address(192.168.1.51) in host filed

Lets assume that you want to connect another server called audio.joomla.com so
you just copy and past your joomla installed folder i.e. /var/www
into new server in the folder /var/www
and chenge the configuration.php file as follows:

host = 192.168.1.51 (your database server ip)

Tuesday, May 17, 2011

How to Clone Whole Hardisk with Ubuntu operating System

ye command aap ki pori ki pori hard disk ko dosri harddisk main istarha copy kardayti hay kay usko operating system bhi copy hojata hay
aur aap wo harddisk kisi dosray computer main laga kar use karsaktay hain aur sub kuch waysa hi hoga.

aik new harddisk lain jo bilkul usi size/capacity ki ho jis ko aap copy karna chatay hain
Ubuntu main gpart ki madad say pehlay uskay sary partitions delete kar dain phir system restart kar kay nechay di hoi command apply karain.

dd command
--------------

sudo dd if=/dev/sdb of=/dev/sdc

iss command ko istarha parhain gay

disk copy karo "if=/dev/sdb" input disk drive say output drive main "of=/deve/sdc

is kay ilawa aap iss ki madad say pori harddisk ki ISO file bana kar bhi backup lay saktay hain
is kay liye nechay wali command use karain

sudo dd if=/dev/sdb of=/home/shaheer/thumbImage.img
------------------------------------------------End-----------------------------------------------

hosakta hay kay jab aap ye hard disk apnay dosray system main lagain to wahan 
Network Card conflict kar jaen ye is liye hota hay kay aap k Ubuntud main MAC address purana wala 
hi  hota hay aur new system main Network Card dosra aajata hay

Following is the solution for this Problem: 


 “SIOCSIFADDR: No such device eth0″

After a bit of googling I found a solution that required editing /etc/ftab to remove an incorrect generated mac address. Hardy Heron doesn’t have this file though so I did a bit more searching around the filesystem and found a reference to the mac address stored in the vmx (vmware config) file found in /etc/udev/rules.d/70-persistent-net.rules. Note: For Debian the file can be found at /etc/udev/rules.d/z25_persistent-net.rules
Method One – delete the rules file

Quickest way to solve this is to move/delete the rules file. (Thanks to the comment from SonniesEdge.)

Ubuntu
sudo mv /etc/udev/rules.d/70-persistent-net.rules /etc/udev/rules.d/70-persistent-net.rules.old

Debian
sudo mv /etc/udev/rules.d/z25_persistent-net.rules /etc/udev/rules.d/z25_persistent-net.rules.old

Now reboot the system so that rule file will be recreated by the Ubuntu

-------------------------------------------------------------------------------------------------------


Method Two – edit the rules file

The second way is to comment out the line relating to eth0 which had the wrong mac address and replaced “eth1″ with “eth0″. After rebooting eth0 should be working properly and normality will be restored.

Here’s an example carried out on Ubuntu.

The old /etc/udev/rules.d/70-persistent-net.rules looked like this:
# PCI device 0x1022:0x2000 (pcnet32)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:50:xx:xx", ATTR{type}=="1", NAME="eth0"

# PCI device 0x1022:0x2000 (pcnet32)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:36:xx:xx", ATTR{type}=="1", NAME="eth1"

Was edited to look like this:
# PCI device 0x1022:0x2000 (pcnet32)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:3