Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

how to upgrade unbuntu kernel


Follow below steps to upgrade Ubuntu Kernel
#uname -a                                         #Check current Kernel version
#aptitude search linux-image              #Check which is the latest version
#aptitute install update
#aptitute install linux-iamge_***  -y
#reboot                                            #reboot the system to take effect the new change

how to mount linux/fedora/Ubuntu folder from different Linux system without installing samba or nfs

Follow the steps to mount linux/fedora/Ubuntu folder from different Linux system without installing samba or nfs .
sshfs and fuse-sshfs allow to mount folder of networked systems using ssh port(22).
Step 1: Install sshfs into Ubuntu
root#apt-get install sshfs
Install sshfs into RHEL or Fedora
root#yum install fuse-sshfs
Step 2: Create a folder to mount
root#mkdir -p /opt/ssh-folder
Step 3: Run below command to mount and press enter.
root# sshfs -o nonempty,noatime -p 22 username@192.168.xxx.xx:"/home/test-folder" /opt/ssh-folder/
Step 4: It will prompt to enter password, type passsword and press enter
username@192.168.xxx.xx's password:******
Step 5: Run mount to check the 192.168.xxx.xx:"/home/test-folder is mounted or not.
root#mount

netcat to transfer files between linux and windows


netcat in windows On Source PC(Windows) download and copy nc.exe  netcat works as a Server and Client model.
Below steps show how to copy data from a Windows system into Linux(Ubuntu) system.Currently I am using Ubuntu Server.Varify
Windows System IP :192.168.xxx.xx  and   Linxu(Ubuntu) system IP: 192.168.yyy.yy
                             Copy files from Windows To Linux
Setp1:Download netcat into Windows System and copy nc.exe into the directory where your file is exist.
Ex: C:\test\nc.exe
Step 2:Install netcat on ubuntu
#apt-get install netcat
Step 3: Now netcat is available on both Windows and Linxu(Ubuntu)
Open command prompt and go to the directory where your file is located and run below command.This will act as a Server.
C:\test> type  backup.iso | nc.exe  -l -p 3333  
Note: "type" is a command in windows.
Step 4: Receive backup.iso on the client machineLinux(Ubuntu) with the following.This will act as a Client
 # nc 192.168.xxx.xx 3333 > backup.iso              
Issue a ^C on the source system and your done one u see file size in destination directory. Be sure to check the file to be sure it is the same size as the original.
                               Copy files from Linxu to Windows 
On Linxu system run below command. Now this will act as a Server
#cat backup.iso | nc -l -p 3333            
On Windows Run below command. Now this will act as a Client.
C:\test> nc.exe 192.168.yyy.yy 3333 > backup.iso
Issue a ^C on the source system and your done one u see file size in destination directory. Be sure to check the file to be sure it is the same size as the original.



Linux filesystem

/ : This(/) is the root folder, all other folders come under root.. it is like C: drive in a Windows OS
/boot : Linux kernel and boot loader configuration files
/usr  : This folder and its sub-folders contains user installed programs and utilities and libraries.It is like
Program files in windows.
/etc  : Configuration files of all installed softwares or applications
/var  : This folder contains files that change alot (“Variable files”). Mail, print web spool files
/tmp  : Temp directory
/home : This folder contains the home folders of all the normal (non – root ) users on the system
/dev  : Device files corresponding to various peripherals of your comp. (hard disk, printer, mouse, modem)
/mnt  : Devices mounted onto OS to increase storage space
/lost+found : Orphan files are moved here
/root : Root's home directory
/proc : Process information pseudo filesystem.
/bin  : various console utilities and apps
/sbin : system administration utilities
/lib  : Shared Library files for your operating system.

restore grub in vyatta router


grub> linux /boot/vmlinuz root=/dev/sda1
grub> initrd /boot/initrd.img
grub> boot
Agter reboot run below command to re-install grub
grub-install /dev/sda
reboot  ##Reboot again to so that the Server will boot normally

useradd in ubuntu

The useradd command will let you add a new user easily from the command line:
#useradd username
Ex : useradd user1
This command adds the user, but without any extra options your user won’t have a password or a home directory. You can use the -d option to set the home directory for the user. The -m option will force useradd to create the home directory.
We will try creating a user account with those options, and then use the passwd command to set the password for the account. You can alternatively set a password using -p on the useradd command, but I prefer to set the password using passwd.
#useradd -d /home/user1 -m user1
#passwd user1
Important locations for users
    * /etc/passwd - User account information.
    * /etc/shadow - Secure user account information such as password.
    * /etc/group - Group account information.
    * /etc/default/useradd - Default values for account creation.
    * /etc/skel/ - Directory containing default files.
    * /etc/login.defs - Shadow password suite configuration.

Add Swap Partition in Linux/Ubuntu

  Create a 512MB swap file
  #dd if=/dev/zero of=/mnt/new.swap bs=1M count=512
  Change Permission to new.swap
  #chmod 600 /mnt/new.swap
  Formatting that file to create a swapping device:
  #mkswap /mnt/512Mb.swap
  Adding the swap to the running system:
  #swapon /mnt/512Mb.swap
  To check swap info
  #cat /proc/meminfo.
 Making the change permanent, open fstab 
 #  vi /etc/fstab
Add below line at the end of the file and save.
/mnt/new.swap none swap sw 0 0

Fastest way of transferring files between 2 server's over network in Linux

Fastest way of transferring files between 2 server's over network in Linux

-- SCP :  It showed 20MB/sec
-- FTP : Requires ftp installed id/password  : 40MB/sec
-- NetCAT : Might work if netcat is installed.  : 60MB/sec      
   source : tar -cvzf /dir/ |netcat -l 7777
   client :  netcat source_ip:7777 |tar -xvzf path

-- Using Python / WGet  : 80MB/sec

Server:
 # cd $folder_have the file
 # Start python webserver with this command.
 python -m SimpleHTTPServer
Client :
 wget -c http://Server IP:8000/$file
-c will recover from a file break if something broke half way.


change boot order for dual boot(Windows XP and Ubuntu)

If you installed Windows and Ubuntu as dual boot then by default windows will boot 1st. To change the boot order we need to change the boot order.

Change default operating system at boot
 To change which operating system starts by default when the computer starts up, edit the grub configuration file.
1.Make a backup of the configuration file, and open it in a text editor:
  cp /boot/grub/menu.lst /boot/grub/menu.lst backup-menu.lst  ### this will to keep a backup of original file
  vi /boot/grub/menu.lst  ### open menu.lst file
2. Find “default 0” line in the menu.lst file
   Ex: type /default and press enter to go to that line.
3. Replace with the following line:
      default X

    Note: You should replace X with a number, according to the order which your operating systems appear in the configuration file. You should start counting from 0. For example, if you wish the default operating system to be the first in the list, replace X with 0, if you wish the default operating system to be the second in the list, replace X with 1, and so on.

post configuration of mysql in ubuntu : allow database access to remote system

Configuration changes on MySQL to accept remote connections from a particular ipaddress

    If you are using Debian Linux file is located at /etc/mysql/my.cnf location
    If you are using Red Hat Linux/Fedora/Centos Linux file is located at /etc/my.cnf location
    If you are using FreeBSD you need to create a file /var/db/mysql/my.cnf

now edit my.cnf depending on your Linux
vi /etc/mysql/my.cnf

Make sure line skip-networking is commented
Add line, go to the line bind-address and repalce 127.0.0.1 to your sql server IP
bind-address=YOUR-SERVER-IP
exit my.cnf file after saving...
/etc/init.d/mysql restart

  open mysql prompt
 mysql -u root -p mysql
 GRANT ALL ON yourdatabasename.* TO username@'your-ipaddress' IDENTIFIED BY
'PASSWORD';

Note: your databasename is replace by your database name and your-ipaddress  is replaced by ip address of remote machine from  which you want to connect to MySql database

installation of SugarCRM in ubuntu server

Below packages required to Installed SugarCRM. In 2 different Ubuntu Server.
Ex: Server-01: Apache and PHP & Server-02: Database Server (MySQL)
Install all the required packages using the following commands on Server-02
sudo apt-get install mysql-server

Install all the required packages using the following commands on Server-01
sudo apt-get install apache2
sudo apt-get install libapache2-mod-php5 libapache2-mod-perl2
sudo apt-get install php5 php5-cli php5-common php5-curl php5-dev php5-gd php5-imap php5-ldap unzip
sudo apt-get install php5-mhash php5-mysql php5-odbc curl libwww-perl imagemagick

Creating Database for SugarCRM
mysql -u root –p
Then type your MySQL password and run this command
mysql> create database sugarcrm;
mysql> exit


Follow the steps to allow access of MySql form remote server or system
Loging into mysql server. Now need to edit my.cnf depending on your Linux
vi /etc/mysql/my.cnf
Make sure line skip-networking is commented.
Go to the line bind-address and replace 127.0.0.1 to your mysql server IP, the new line should look like below..
bind-address=YOUR-SERVER-IP
exit my.cnf file after saving...
/etc/init.d/mysql restart
  open mysql prompt
 mysql -u root -p mysql
 GRANT ALL ON yourdatabasename.* TO username@'your-ipaddress' IDENTIFIED BY
'PASSWORD';
*yourdatabasename is replace by your database name,your-ipaddress  is replaced by ip address of remote machine from which you want to connect to MySql database

Installed SugarCRM
Now you need to go to your webserver document root directory (default location is /var/www) or your choice…
cd /var/www
Download SugarCRM

Now unzip file for using this command
unzip SugarCE-6.1.2.zip
Changed the folder name
sudo mv SugarCE-6.1.2.zip sugarcrm
Changed the ownership of this folder
sudo chown –Rf www-data:www-data sugarcrm
Give Write permitions for apache on some of SugarCRM Files
cd /var/www/sugarcrm
sudo chmod 766 config.php
sudo chmod 766 custom
sudo chmod -R 766 data
sudo chmod -R 766 cache
sudo chmod -R 766 modules

Open php configuration file do below chane
vi /etc/php5/apache2/php.ini
Change
;memory_limit = 16M  to memory_limit = 50M
Change
;upload_max_filesize = 2M to upload_max_filesize = 10M
Restart web server using the following command
sudo /etc/init.d/apache2 restart

Configure sugarCRM
Now open your webbrowser and enter the following address
http:// hostname or server-ip/sugarcrm/install.php
While configuring give mysql server ip and password as we have installed mysql database on different server.


ftp(File Transfer Protocol) server installation and configuration in linux

Before install and configuration of ftp server in linux.The ftp server called in linux is vsftpd(Very Secure FTP Daemon). Default ports for FTP are 20 and 21.
Port 20 is used for Data Channel or Data Communication(Upload or Download Data).
Port 21 is used for Control Channel or  establish connection

Install vsftpd in linux:  yum install vsftpd*
If we have download rpm of  vsftpd then got the directory and ran below command
rpm -ivh vsftpd*
Once vsftpd is installed, it will create a default directory in /var/ftp/pub . By default vsftp allow only download.

To enable upload we need create a folder in /var/ftp/pub and  allow download in vsftpd configuration file.
vsftpd.conf is a configuration of vsftpd located in /etc/vsftpd/.
1.Create download folder in /var/ftp/
mkdir -p /var/ftp/download
chmod 777 /var/ftp/downlad ###give full permission to download folder
2.Open vsftpd.conf and allow download
vi /etc/vsftpd/vsftpd.conf
Uncomment or remove "#" form line number 27th   ###This will enable uploading
Uncomment or remove "#" form line number 83rd  ###This will provide message to user
Uncomment or remove "#" form line number 27th  ###This will enable log file option. By default vsftpd doesn't creat any log file. Once we enable log then a log file will be created as vsftpd.log in /var/log/vsftpd.log
Need to restart vsftpd service to effect the chanes.
service vsftpd restart ### The settings temporary
chkconfig vsftpd on  ### Settings saved permanently

 Commands to  connect ftp server and upload or download data.
ftp   
ls                  ###List
get               ### Download data
mget            ### Download multiple
mget *         ###Download complete data
put              ### Upload Data
mput           ###Upload multiple files or folders
mput *        ###Upload complete data
!                 ### Exit form ftp session temporarily
exit            ### To back to ftp session
lcd /opt      ### Change Directory
bye           ### Quit ftp session
prompt     ### To enable or disable passive mode



inittab file in ubuntu and linux

There is no /etc/inittab file in Ubuntu because Ubuntu has /etc/event.d/rc-default file
runlevel  # to check current runlevel
The following runlevels are defined:
       N      System bootup (NONE).
       S      Single user mode (not to be switched to directly)
       0      halt
       1      single user mode
       2 to 5 multi user mode
       6      reboot

mkfs blkid fstab

mkfs: This command stands for make file system and it is used to format the partition by using file system.

Syntax: mkfs.
       Ex: mkfs.ext3 /dev/hdb
             mkfs.ext4 /dev/hda
blkid: This command is used to check file-system type of partion.

Ex: blkid /dev/hda

fstab: This is one of the inbuilt file of linux which is used to mount partition permanently across the reboot.


partition tools in linux

We can create linux partition in 2 ways. i.e. Pre-Installation and Post-Installation
Pre-Installation partition is Disk Druid
Post-Installation  partition tools are
fdisk
cfdisk
sfdisk
parted

Expand/Increase ext3 root partition

Please follow the steps to Expand/Increase ext3 root Partition of a VMware Server disk (.vmdk)

Step-1 Shutdown the VM which you want to Expand/Increase ext3 root partition.
Step-2 Backup your original VMDK file to a different location
Step-3 Now we can Expand/Increase the disk
Syntax:vmware-vdiskmanager -x (Which you want to expand)
EX:vmware-vdiskmanager -x 50GB yyy.vmdk
If the command ran successful then you will get below message.
=================================================================
Disk expansion completed successfully.
WARNING: If the virtual disk is partitioned, you must use a third-party
utility in the virtual machine to expand the size of the
partitions. For more information, see:
http://www.vmware.com/support/kb/enduser/std_adp.php?p_faqid=1647
==================================================================
Now disk size is increased but operating system will only show old size.To add new disk we will need to use a third-party utility such as GParted to resize the expanded partitions. The GParted application is the GNOME partition editor for creating, reorganizing, and deleting disk partitions. GParted is a live Linux based CD.
Step-4 Download latest version here or use wget command
http://nchc.dl.sourceforge.net/sourceforge/gparted/gparted-live-0.4.5-2.iso
or
cd /tmp
wget http://nchc.dl.sourceforge.net/sourceforge/gparted/gparted-live-0.4.5-2.iso
Step-5 Boot the VM with GParted ISO.
Once the vm boots up, Press enter to go to next screen. Press enter till you get the GParted Screen.
Step-6 Right click on the partition which you want to expand and select "Resize/Move"
Step-7 Set a new size to maximum size (it is displayed on the screen itself) and Finally, Click on Resize/Move button to start the process.
Step-8 Click "Apply" to run the resize task. Depending on the amount (disk size and storage type) and type (resize or move) operation resize may tae a long time. After sometime Gparted will give out the final confirmation about disk resize operation (you must not get any error on screen)
Step-9 Click on Close and then exit to shutdown Gparted.
Step-10 Remove the GParted ISO and boot the vm with HDD
Step-11 Login into vm and verify the new disk size.

ADD/DELETE/MODIFY IPTABLES firewall RULE in DD-WRT ROUTER

For example I am allowing ping request to DD-WRT router. Below iptables commands can be used on any Linux Operating System.

We can't to ping dd-wrt router's public or private ip because of iptables firewall rule. By default iptables drop ICMP request. If you want to allow ping then we need to allow ping in dd-wrt router.For allowing ping to ip of DD-WRT Router), we need to run iptables rule because I did not find any option to allow ping to lan ip.
Some useful iptables commands
# The default behaviour => accept connections
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT
# Allow ESTABLISHED and RELATED incoming connection
iptables -A INPUT -i eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT
# Allow loopback traffic
iptables -A INPUT -i lo -j ACCEPT
#Allow ICMP
iptables -A INPUT -p icmp -i eth0 -j ACCEPT
#Do not allow ICMP
iptables -A INPUT -p icmp -i eth0 -j DROP
# Below command will show list of INPUT rules with line numbers
iptables -L INPUT --line-numbers
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 ACCEPT udp -- anywhere anywhere udp dpt:12345
2 ACCEPT 0 -- anywhere anywhere state RELATED,ESTABLISHED
3 DROP udp -- anywhere anywhere udp dpt:route
4 DROP udp -- anywhere anywhere udp dpt:route
5 ACCEPT udp -- anywhere anywhere udp dpt:route
6 logaccept tcp -- anywhere DD-WRT tcp dpt:www
7 logaccept tcp -- anywhere DD-WRT tcp dpt:ssh
8 DROP icmp -- anywhere anywhere
9 DROP igmp -- anywhere anywhere
10 ACCEPT 0 -- anywhere anywhere state NEW
11 logaccept 0 -- anywhere anywhere state NEW
12 DROP 0 -- anywhere anywhere
#Below command will replace rule no 8 in iptables firewall and it will allow icmp request
iptables -R INPUT 8 -p icmp --icmp-type echo-request -j ACCEPT
-R = will repalce the iptables rule
8 = Rule no 8
#Disable iptables rule number wise
iptables -R INPUT 8 -p icmp --icmp-type echo-request -j DROP
#Delete iptables rule number wise
iptables -D INPUT 8
-D=Delete rule
8= Rule no 8