Showing posts with label howto. Show all posts
Showing posts with label howto. Show all posts

How To Format Disk in linux

In the previous post we discussed how to re-size disk space,
Now lest say you want to add additional disk to your machine.

Follow the commands: 

step 1 -  Partition
# fdisk -l | grep Disk
Disk /dev/sda: 549.7 GB, 549755813888 bytes
Disk /dev/sdb: 107.3 GB, 107374182400 bytes 

you'll see the disks on your machine, we want to partition the new disk /dev/sdb

# fdisk /dev/sdb
n - add new partition - follow the instruction
p - print the partition table - check the partition
w - write table to disk and exit

step 2 - Format

mkfs.ext3 /dev/sdb1

step 3 - Mount
# mkdir /New-Disk
# mount /dev/sdb1 /New-Disk

step 4 - Update /etc/fstab
# vi /etc/fstab
add the next line to the file:
/dev/sdb1     /New-Disk     ext3     defaults     1 2
Save and close the file.

Now check the changes:
# df -h
Read more >>

How To display Timestamp in History command



By default, the history command shows just the command number and the command.
it could be very useful to add a timestamp to be shown, this can help you to monitor things by the time you run something.

To add the timestamp you need to export the next command:
#  export HISTTIMEFORMAT='%F %T '

if you want, you can add this line to your profile, so next you boot your machine, it will run automatic:
just edit /etc/profile  and add the line above.

Best Regards
Read more >>

How to resize ext3 partition - GPartEd

Hi, couple of days ago was asked to increase ext3 partition without LVM.
After searching the web I found a cool Linux Live CD called GPatrEd.
because it has just one partition  " /dav/sda1 on / "  i could not unmount it the resize it with the new space.
I was had to used a live CD.
I'm talking about virtual machine, so first I increased the disk space of the virtual machine
then I restart and boot from GPartEd live CD.
The UI is very simple and fun actually, 
all you need to do is to resize the partition with the mouse the click APPLY.






After finishing, I restart the machine again and WALLA I had new partition space on my server.







Read more >>

How To install Load Balancer with HAProxy on Debian

Hi, today I want to discuss on how to install a LB for web servers base on http (linux or windows) on debian.

Installation:
First we need to add the source of the installation to sources.list
# vi /etc/apt/sources.list

and add the following lines:
deb http://ftp2.de.debian.org/debian/ etch main
deb-src http://ftp2.de.debian.org/debian/ etch main

deb http://ftp2.de.debian.org/debian/ lenny main

deb http://security.debian.org/ etch/updates main contrib
deb-src http://security.debian.org/ etch/updates main contrib

Next we need to update the sources and install the HAproxy

# apt-get update
# apt-get install haproxy

Configuration:
First we backup the original configuration
# cp /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.orig
# cat /dav/null > /etc/haproxy/haproxy.cfg

and new we create a new configuration for our Round Robin LB.
edit the haproxy.cfg file and add the following lines:
# vi /etc/haproxy/haproxy.cfg
global
        log 127.0.0.1   local0
        log 127.0.0.1   local1 notice
        maxconn 4096
        user haproxy
        group haproxy

defaults
        log     global
        mode    http
        option  httplog
        option  dontlognull
        retries 3
        redispatch
        maxconn 2000
        contimeout      5000
        clitimeout      50000
        srvtimeout      50000

listen webfarm LB-IPAddress:80
       mode http
       stats enable
       stats auth someuser:somepassword
       balance roundrobin
       cookie JSESSIONID prefix
       option httpclose
       option forwardfor
       server webA serverA-IP:80 cookie A check
       server webB serverB-IP:80 cookie B check

make sure you change the RED lines to your settings.
 
and now we need to ENABLE the haproxy in /etc/default/haproxy
# vi /etc/default/haproxy
and set ENABLE=1

to start haproxy just run:
# /etc/init.d/haproxy start


that's it you have a Load Balancer Installed and work.

HAproxy Statistics:
In this configuration we enable the statistics of haproxy, you can acsses from you browser by enter http://LB-IPAddress/haproxy?stats


The user and the password is like you type in the configuration in "stats auth someuser:somepassword"

Enjoy and please comment !!!



Read more >>

How To install Apache MySQL and PHP

The easy way to install a web server with apache MySQL and PHP is by a project called XAMPP
XAMPP is a project of apache friends how let you the easy way to install Apache distribution containing MySQL, PHP and Perl.

I was trying to create a new WordPress blog on one of my servers. and I found this project very helpful.
All you have to do is to download a tar file from from XAMPP website untar him and thats it.
I will show you how it goes:

Download the last version of XAMPP from here - http://www.apachefriends.org/en/xampp-linux.html#374
Run the command:
tar xvfz xampp-linux-1.7.3a.tar.gz -C /opt

That's all. XAMPP is now installed below the /opt/lampp directory.
All you need to do to start the XAMPP is:
# /opt/lampp/lampp start

You should now see something like this on your screen:Starting XAMPP 1.7.3a...
LAMPP: Starting Apache...
LAMPP: Starting MySQL...
LAMPP started.


Go to your server via you browser ~ http://localhost




for more information and tricks go to the main project website - http://www.apachefriends.org/
Read more >>

How To make SSH Tunnel

Hi,
In this post I'll discuss no how to make ssh tunnel
this how to will show you the basic, and I hope you will take the good from it to your needs.

the main configuration is:
edit /etc/ssh/ssh_config with your favorite editor
# vi /etc/ssh/ssh_config
and add flowing lines in the end

Host test
HostName localhost
User your_user_name
LocalForward 2022 SERVER1_IP:22
LocalForward 2080 SERVER2_IP:80
LocalForwars 2025 SERVER3_IP:25


save the file.
and run: # ssh test
now if you'll try to access to localhost on port 2080 you'll go to SERVER2 on port 80, you can test it from your browser - http://localhost:2080/ or try to ssh to locahost with port 2022
# ssh -p 2080 localhost

and you'll see you go to SERVER1.

You can run the ssh tunnel from one command line instead of edit the ssh_config.
# ssh -N -f User_Name@SERVER2_IP -L 2080/localhost/80
this script tell the server to forward all the traffic to port 2080 to SERVER2 on port 80

Or if you want to make REVERSE tunnel you can run the same command but with -R instead of -L
# ssh -N -f User_Name@SERVER2_IP -R 2022/localhost/22
(with this script you can access from the remote machine (SERVER2) via ssh to your machine with port 2022)
run # ssh -p 2022 localhost from SERVER2

I'm hoping this post will help you to understand the basic of ssh tunneling
Please comment
Read more >>

HowTo Install NRPE on Debian-Host

Hi,
Later in my last post - How To Install Nagios
I want to show you how to install NRPE plugin on your Debian-Hosts to monitoring from Nagios.

Install NRPE-Daemon and Nagios-Plugins on Debian-Linux Host.

1. Make sure you have a C compiler installed
# apt-get install make gcc g++

2. Install SSL for secure communication between Nagios-Server and Debian-Host
# apt-get install libssl-dev

3. Install SNMP (in case you like to query some SNMP via NRPE)
# apt-get install snmpd
# apt-get install snmp scli tkmib

4. Create Nagios user
# useradd -p nagios nagios

5. Install Nagios-Plugins
# cd /usr/src
# wget http://internode.dl.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.13.tar.gz
# tar -xzvf nagios-plugins-1.4.13.tar.gz
# cd nagios-plugins-1.4.13
# ./configure
# make
# make install

6. Fix permission for the Nagios director
# chown -R nagios:nagios /usr/local/nagios/

7. Install Xinetd
# apt-get install xinetd

8. Install and configure NRPE
# cd /usr/src
# wget http://waix.dl.sourceforge.net/sourceforge/nagios/nrpe-2.12.tar.gz
# tar -xzvf nrpe-2.12.tar.gz
# cd nrpe-2.12
# ./configure
# make all
# make install-plugin
# make install-daemon
# make install-daemon-config
# make install-xinetd

Edit /etc/xinetd.d/nrpe
# vi /etc/xinetd.d/nrpe
and add to only_from= your Nagios server IP
only_from = 127.0.0.1 192.168.1.101

Add the following entry for the NRPE daemon to the /etc/services file.
# echo "nrpe 5666/tcp #NRPE" >> /etc/services

Restart the NRPE service
# /etc/init.d/xinetd restart

Test if NRPE is listening:
# netstat -l | grep nrpe

The output out this command should show something like this:
tcp 0 0 *:nrpe *:* LISTEN

Next, check to make sure the NRPE daemon is functioning properly. To do this, run the check_nrpe plugin that was installed for testing purposes.
# /usr/local/nagios/libexec/check_nrpe -H localhost

If everything is fine you will see this output:
NRPE v2.12

9. Test the NRPE from the Nagios-Server
Now we want to test if we can query some information from the Debian-Host via NRPE from the Nagios-Server.
So switch into /usr/local/nagios/libexec on your Nagios Server and check if you have the check_nrpe plugin.
# ls - l check_ nrpe

In case you dont have the check_nrpe plugin you need to download and compile NRPE. (See Step 8)
run the next command:
# ./check_nrpe -H HostIPAddress -c check_users

You should get something like this back:
USERS OK - 1 users currently logged in |users=1;5;10;0

Great! Your Nagios server is able to communicate with the Debian-Host.
Read more >>

How To Install Nagios on Ubuntu

Nagios is a powerful monitoring system that enables organizations to identify and resolve IT infrastructure problems before they affect critical business processes.

Download, install and Configure Apache
first we have to install some necessary compliers and Apache to run Nagios.
run the next commands:
# sudo apt-get install build-essential
# sudo apt-get install libgd2-xpm-dev
# sudo apt-get install apache2
# sudo apt-get install php5-common php5 libapache2-mod-php5

Configure Apache to use PHP:

Run in a terminal:
# sudo vi /etc/apache2/apache2.conf
Paste the following into the file:
DirectoryIndex index.html index.php index.cgi

and restart the server with the command
# sudo /etc/init.d/apache2 restart

Download, install, and configure Nagios
Create a user to run the service and a group to run external commands:

# sudo useradd -m nagios
# sudo passwd nagios
# sudo groupadd nagcmd
# sudo usermod -a -G nagcmd nagios
# sudo usermod -a -G nagcmd www-data

Download the current version of Nagios and Nagios Plugins from - http://www.nagios.org/download/

Extract the Nagios tar:
# sudo tar -zxvf nagios-3.1.2.tar.gz
and change to the nagios-3.1.2 directory
# cd  nagios-3.1.2
Now install the Nagios use the flowing commands :
# sudo ./configure --with-command-group=nagcmd
# sudo make all
# sudo make install
# sudo make install-init
# sudo make install-config
# sudo make install-commandmode
# sudo make install-webconf

Add a user for the Nagios interface:
# sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

Extract and compile the Nagios-plugins:
# tar -zxvf nagios-plugins-1.4.14.tar.gz
# cd nagios-plugins-1.4.14
# sudo ./configure --with-nagios-user=nagios --with-nagios-group=nagios
# sudo make
# sudo make install

Create a link to start the service:
# sudo ln -s /etc/init.d/nagios /etc/rcS.d/S99nagios

Verify the config:
# sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Start Nagios:
# sudo /etc/init.d/nagios start

You should now be able to log into the Nagios web interface (http://localhost/nagios) using the nagiosadmin user and password.
Read more >>

How To change user name and UID

Hi,
I was asked to change the ID of the mysql user and gourp on one of my servers.
this is a very simple to do.

first type
# id mysql
uid=101(mysql) gid=103(mysql) groups=103(mysql) 
to change the user id type:
# usermod -u 25 mysql
to change the group id run the next command under root user:
# vigr
search the mysql group mysql:x:103: the change it to 25 mysql:x:25:
(save with /wq like regular vi)
OR
# groupmod -g 25 mysql
now run again:
# id mysql
uid=25(mysql) gid=25(mysql) groups=25(mysql)

to change user name run:
# usermod -l old_name new_name
to change home directory run:
# usermod -d /home/user_name user_name
to change group name run:
# groupmod -n old_name new_name
Read more >>

How to configure MySQL Cluster with Heartbeat

In this post we'll discuss how to set up a MySQL cluster with two serves, storage and Heartbeat.
I'm using CentOS 5 distribution on both machines, MySQL 5.1 and a mounted directory on both servers to /var/lib/mysql

Pre-Configuration
You need to install MySQL on both machines.
Assign hostname dbserver01, dbserver02.
dbserver01 is the primary node with IP address 192.168.1.101 to eth0.
and dbserver02 is the slave one with ip address 192.168.1.102.
192.168.1.103 is the virtual IP that will be used for MySQL.

Configuration (do those steps on both servers)
install the Heartbeat package:
# yum install heartbeat

copy the next configuration files to the /etc/ha.d directory:
# cp /usr/share/doc/heartbeat-version/authkeys /etc/ha.d
# cp /usr/share/doc/heartbeat-version/ha.cf /etc/ha.d
# cp /usr/share/doc/heartbeat-version/haresources /etc/ha.d

First we will edit the authkeys file,
# vi /etc/ha.d/authkeys
copy from here:
auth 2
2 sha1 test-HA
change the permission of the authkeys file:
# chmod 600 /etc/ha.d/authkeys

Now let's edit the most important file (ha.cf)
# vi /etc/ha.d/ha/cf
add the following lines into the file:
logfile /var/log/ha-log
logfacility local0
keepalive 2
deadtime 30
initdead 120
bcast eth0
udpport 694
auto_failback on
node dbserver01
node dbserver02 

The last file we need to edit is haresources:
# vi /etc/ha.d/haresources
add the following line:
dbserver01 192.168.1.103 netfs mysqld 

Now all we need to do is to start the hearbeat service on both machines:
# /etc/init.d/heartbeat start
the virtual IP address 192.168.1.103 is now on dbserver01 and MySQL is up and running.
if dbserver01 will crashed from any reason the IP address will jump to dbserver02 the the MySQL service will start automatic.

Enjoy.
And please comment (-;
Read more >>

How to mirror a folder among 2 servers

Hi, in this post I'll show you how to mirror ,synchronize a folder from serverA to serverB with rsync for a backup purpose or what ever you want and need.

First we have to install rsync on both machines for RedHat/Fedora/CentOS you would use:
# yum install rsync
for Debian systems:
# apt-get install rsync
or if you work with SuSE use: yast


Now we need to create a user that will be used by rsync on both servers:
# useradd -d /home/syncuser -m -s /bin/bash syncuser
and give this user a password:
# passwd syncuser


The next step is to make sure that serverA can log into serverB without password so we could create a crontab script which do the synchronization automatic without human interaction.
for this step please go read my post - how to ssh without password

After we test we can ssh from serverA to serverB without password, we can test the rsync,
make sure you have a folder on serverB that you want to backup all your data to and run the next command on serverA:
# rsync -raz --progress --size-only --delete /DirOnServerA/* syncuser@serverB:/DirOnServerB


Now go the serverB and check if you data are there.

All you left to do is to to add the rsync script to crontab and you can sleep well at night.




.
Read more >>

How to mount dir via NFS

Hi, for mount dir from another server you have to use NFS service
NFS - Network File System
First we need to install nfs service on both servers.
logon to your server with root user, and run:

# yum install nfs-utils nfs-utils-lib nfs-utils-lib-devel

After installation finished we need to tell the client machine (the one with the existing folder) that we want to share a folder.
edit /etc/exports like this:

# vi /etc/exports
and add the next line:
/the/folder/you/want *(rw,no_root_squash,async)

Now you need to be shore the NFS ports are open on your server: 2049/tcp 2049/udp and 111/tcp 111/udp

After everything done you can start the NFS service on both machines by:

#/etc/init.d/nfs start

Now you can mount your dir via NFS but first you need to open a folder to the mount one, by:

# mkdir /mnt/DIR
# mount servername:/the/folder/you/want /nmt/DIR

that's it, you done.

If you want the mount to be permanently (mount automatic when restart), you can do it by edit fstab file
and add it the next line:

# vi /etc/fstab
/servername:/the/folder/you/want /mnt/DIR nfs defaults 0 0
# mount -a


ENJOY.
Read more >>

How to add a Swap file

Sometimes it is necessary to add more swap space after installation. For example, you may upgrade the amount of RAM in your system. It might be advantageous to increase the amount of swap space if you perform memory-intense operations or run applications that require a large amount of memory.
You have two options: add a swap partition or add a swap file. It is recommended that you add a swap partition, but sometimes that is not easy if you do not have any free space available.

At a shell prompt as root, type the following command with count being equal to the desired block size:

# dd if=/dev/zero of=/swapfile bs=1024 count=1024000

in the count type the amount of space you wont for your swap file. For example, 1024000=1GB

Setup the swap file with the command:
# mkswap /swapfile

To enable the swap file immediately but not automatically at boot
# swapon /swapfile
Or use # swapoff /swapfile to disable the mount.

To enable it at boot time, edit /etc/fstab to include:
# vi /etc/fstab
/swapfile               swap                    swap    defaults        0 0

The next time the system boots, it will enable the new swap file.
After adding the new swap file and enabling it, make sure it is enabled by viewing the output of the command
# cat /proc/swaps
or
# free
Read more >>

How To Replicate MySQL Database - Step 2

Go Back Step 1

Getting the data to the Slave.


On the Master Server
I'm assuming you have a live Master server, and an as yet empty Slave server. This stage depends on whether data is constantly being added to the Master. If so, we will have to prevent all database access on the Master so nothing can be added. This means your server will hang during the next step. If no data is being added to the server, you can skip this step. On the Master server, log into MySQL and do the following:
# mysql -u root -p
   Enter password:
   FLUSH TABLES WITH READ LOCK;
   exit;

Now we will use mysqldump to get the data out. So, still on the Master server:


# mysqldump my_database -u root -p > /tmp/database.sql;
# gzip /tmp/database.sql;

Make sure you change my_database to your database name. You will now have a file called database.sql.gz in your temp directory. This is a gziped copy of your database.

On the Slave Server
Now we need to copy over the gzipped file. On the Slave run the following:
# scp root@192.168.1.100:/tmp/database.sql.gz /tmp/



Make sure 192.168.1.100 is the IP of the Master. This will copy the file from the Master and put it in your temp directory on the Slave. Now we just need to import into MySQL:
# mysql -u root -p
   Enter password:
   CREATE DATABASE `my_database`;
   exit;
# gunzip /tmp/database.sql.gz
# mysql -u root -p
my_database  


Finishing

On the Master Server
 Now we need to find the position the Master is at in the logs. So, log into MySQL and run the following:
# mysql -u root -p
   Enter password:
   SHOW MASTER STATUS;

This should give you an output along these lines:


+--------------------------+-------------+---------------------------+------------------+
| File                     | Position    | Binlog_Do_DB              | Binlog_Ignore_DB |
+--------------------------+-------------+---------------------------+------------------+
| mysql-bin.000001         | 21197930    | my_database,my_database   |                  |
+--------------------------+-------------+---------------------------+------------------+
Keep that on-screen.

On the Slave Server
Log into MySQL and do the following:
# mysql -u root -p

   Enter password:
   slave stop;
   CHANGE MASTER TO MASTER_HOST='
192.168.1.100', MASTER_USER='slave_user',  
   MASTER_PASSWORD='your_password', MASTER_LOG_FILE='mysql-bin.000001',   
   MASTER_LOG_POS=21197930;
   slave start;
   exit;

The Slave will now be waiting. So all that's left is to...

Back to the Master Server
To release the tables from lock, Note you only have to do this if you previously run

   FLUSH TABLES WITH READ LOCK;

We shoud already be logged into MySQL, so all you have to do is:
   unlock tables;
   exit;


Read more >>

How To Replicate MySQL Database - Step 1

Configure the Master Serve

First we have to edit /etc/my.cnf, comment out these lines:
#skip-networking
#bind-address            = 127.0.0.1

Now we need to tell MySql to write a bin-log (these logs are used by the slave to see what has changed on the master)
add these lines to /etc/my.cnf in [mysqld] section:
log-bin = /var/log/mysql/mysql-bin.log
server-id=1

If you want to replicate just one database you may add this line also:
binlog-do-db=my_database

Then restart MySql
/etc/init.d/mysqld restart

Then we log into the MySQL database as root and create a user with replication privileges
# mysql -u root -p
Enter password:
GRANT REPLICATION SLAVE ON *.* TO 'slave_user'@'%' IDENTIFIED BY 'your_password';
FLUSH PRIVILEGES;
exit;

Configure the Slave Server

Again, we have to edit /etc/my.cnf file for the salve server,
add these lines to /etc/my.cnf in [mysqld] section:
server-id=2
master-host=192.168.1.100
master-connect-retry=60
master-user=slave_user
master-password=your_password
#replicate-do-db= my_database
relay-log = /var/lib/mysql/slave-relay.log
relay-log-index = /var/lib/mysql/slave-relay-log.index

Master-host – can be IP or host name of the Master Server
Replicate-do-db – add this just if you want replicate one database.
You should also make sure skip-networking has not been enabled.

Then restart MySql:
# /etc/init.d/mysqld restart 


Read more >>

How to block Root access and use sudo permissions

In my servers Policy I usually block the Root user access via ssh,
and I create an admin user how I give a sudo permissions to manage the server.
for disable Root login edit sshd_config file:
# vi /etc/ssh/sshd_config

search the line #PermitRootLogin yes , remove the # from it and change it to 'no'.
do the same to this line: #StrictModes yes
the section in the sshd_config file should look like this:
#LoginGraceTime 2m
PermitRootLogin no
StrictModes no
#MaxAuthTries 6

now restart the ssh service:
# /etc/init.d/sshd restart

OK, now you block the root access, the next step is to create admin user and give him sudo permissions to the commends you like.
How it work?
#useradd admin
#passwd admin
(Enter any password you want to admin user)


#/usr/sbin/visudo
now you need to edit this file to your needs
first create User alias specification
User_Alias ADMIN = admin
then create Command alias specification
Cmnd_Alias CADMIN = /bin/rm, /sbin/service, /bin/chown, /bin/tar, /bin/cp
you can add here any command you want the user admin will have.
and at last you need to create User privilege specification
ADMIN   ALL=NOPASSWD: CADMIN
in the end the file should look something like this:

# sudoers file.
# This file MUST be edited with the 'visudo' command as root.
# See the sudoers man page for the details on how to write a sudoers file.

# User alias specification
User_Alias ADMIN = admin

# Cmnd alias specification
Cmnd_Alias CADMIN = /bin/rm, /sbin/service, /bin/chown, /bin/tar, /bin/cp

# User privilege specification
root    ALL=(ALL) ALL
ADMIN   ALL=NOPASSWD: CADMIN

That's it.

Read more >>

How to bond Ethernet interfaces

Bonding eth-interfaces

If you need to bonding your Ethernet interfaces, Do the following:
add following lines to the /etc/modprobe.conf file
# vi /etc/ modprobe.conf
alias bond0 bonding
options bonding mode=1 arp_interval=100 arp_ip_target=192.168.1.1
create the file /etc/sysconfig/network-scripts/ifcfg-bond0  with the normal IP setting:
# vi /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
BOOTPROTO=none
ONBOOT=yes
TYPE=Ethernet
IPADDR=192.168.1.40
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
Add eth0 and eth1 to the bonding pair by editing the files:
/etc/sysconfig/network-scripts/ifcfg-eth0 and
/etc/sysconfig/network-scripts/ifcfg-eth1 to look something like this:
DEVICE=eth0
BOOTPROTO=none
HWADDR=00:17:A4:10:D7:32
ONBOOT=yes
TYPE=Ethernet
MASTER=bond0
SLAVE=yes
Restart the network service:
# /etc/init.d/network restart



Read more >>

How to mount your system with live CD

more then once I was needed to reconfigure my ubuntu grub or change the root password of a certain machine.
If you can't login to the machine or you don't have your root password,
the easy way to do so is to mount the system from a live CD.
I'm using Ubuntu 9.04 live CD:

insert the live CD to your cdrom and restart the computer.
chose the first option of the main menu -
"Try ubuntu whitout any change to your computer"


when it finish loading, open the terminal console and run the next commands.
first we need to find your linux partition
# sudo fdisk -l

than we need to mount into it
# sudo mkdir /mnt/root
# sudo mount -t ext3 /dev/sda1 /mnt/root
# sudo mount -t proc none /mnt/root/proc
# sudo mount -o bind /dev /mnt/root/dev
# sudo chroot /mnt/root /bin/bash

That's it, Now you login the machine as root user, and you can do what ever you want.

for reinstall grub you can use grub-install:
# grub-install /dev/sda1
or
# grub
grub> find /boot/grub/stage1
grub> root (hd?,?)
grub> setup (hd?)
grub> quit

or change the root password with passwd:
# passwd root


Read more >>

How to install FTP server

In every company there is a need to send big files that it's impossible to send them by mail.
The most popular way to do it is to install a FTP server.
My favorite FTP package is ProFTPD .


Installation

add user proftpd
# useradd proftpd

download proftpd-1.3.2 from here:


After download the tar file, run:
# tar -zxvf proftpd-1.3.2.tar.gz
# cd proftod-1.3.2
# ./configure --prefix=/usr --sysconfdir=/etc \ --localstatedir=/var/run &&
# make
# make install

Configuration

edit the configuration file
# vi /etc/proftpd.conf

copy/paste the next configuration to your proftpd.conf
ServerName                      "ProFTPD Default Installation"
ServerType                      standalone
DefaultServer                   on
RequireValidShell               off
Port                            21
PassivePorts                    60150 60200
UseReverseDNS                   off
IdentLookups                    off
ServerIdent                     on "Welcome to FTP Server"

AuthPAM                         on

Umask           022

SystemLog       /var/log/proftpd.log

MaxInstances    30

# Set the user and group under which the server will run.
User            proftpd
Group           proftpd

# Added this line to chroot users in their home dirs
#DefaultRoot     /var/www/html
DefaultRoot     ~

# Normally, we want files to be overwriteable.

AllowOverwrite          on


# A basic anonymous configuration, with no upload directories.
#
#User                    ftp
#Group                   ftp

# We want clients to be able to login with "anonymous" as well as "ftp".
#UserAlias               anonymous ftp

# Limit the maximum number of anonymous logins.
#MaxClients              10

# We want 'welcome.msg' displayed at login, and '.message' displayed
# in each newly chdired directory.
#DisplayLogin            welcome.msg
#DisplayChdir            .message

# Limit WRITE everywhere in the anonymous chroot.
#
#DenyAll
#
#
Create a file /etc/pam.d/ftp with the following content
(otherwise you will not be able to log in with system users using FTP):
# vi /etc/pam.d/ftp
#%PAM-1.0
auth    required        pam_unix.so     nullok
account required        pam_unix.so
session required        pam_unix.so

Extras

IF you useing IPTABLE add the lines to you iptable
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 60150:60200 -j ACCEPT
-A OUTPUT -p tcp --dport 22 -j REJECT
IF you want to Deny from FTP users access to the server via ssh run:
# vi /etc/ssh/sshd_config
and copy the next line to the end of the file
#FTP Group Block ssh Access
DenyGroups proftpd
Read more >>

How to ssh without password

On client side, (the machine you want ssh to)
Run the next command.
Use the default settings and an empty passphrase:
# ssh-keygen -t rsa

On the remote machine, (the machine you want ssh from)
Run the next line:
# ssh user@remote test -d \~/.ssh \|\| mkdir \~/.ssh \; cat \>\> \~/.ssh/authorized_keys <~/.ssh/id_rsa.pub
don't forget to change the user@remote to your own one.

OR
you can copy the id_rsa.pub from the clinet machine with :
# ssh-copy-id -i ~/.ssh/id_dsa.pub username@remotebox

END.



Read more >>