Posts

How to Reduce the size of wtmpx file

Step 1: Introduction

The utmpx and wtmpx files are extended database files that have superseded the obsolete utmp and wtmp database files.
The utmpx database contains user access and accounting information for commands such as who(1), write(1), and login(1). The wtmpx database contains the history of user access and accounting information for the utmpx database.

Step 2: Create Backup of wtmpx

In order to create a backup of wtmpx first check the disk space in /tmp and then copy the file in /tmp directory

# /usr/lib/acct/fwtmp < /var/adm/wtmpx > /tmp/wtmpx.orig

Step 3: Empty wtmpx file

To empty wtmpx file us the following command

# cat /dev/null > /var/adm/wtmpx

Step 4: Zip original wtmpx file

Create a zip of original wtmpx file using gzip command

# gzip /tmp/wtmpx.orig

Step 5: Copy original wtmpx

Copy original wtmpx file in /var/adm/ for audit purpose

# cp /tmp/wtmpx.orig.gz /var/adm/

How to Jail FTP User

FTP is built on a client-server architecture and uses separate control and data connections between the client and the server.

Step 1: Prerequisites

To Jail FTP User firstly Configure FTP Server.

Step 2: Modify ftpusers File

Modify ftpusers File in /etc/vsftpd/ftpusers and list the users for jailing.

# vi /etc/vsftpd/ftpusers
root
bin
daemon
adm
lp
sync
shutdown
halt
mail
news
uucp
operator
games
nobody

Step 3: Configure vsftpd.conf File

If we jail ftp user then we make following settings.

# vim /etc/vsftpd/vsftpd.conf
chroot_local_user=YES
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/chroot_list

Step 4: Restart the service

Now restart the service vsftpd

# service vsftpd restart

How to create NFS Server in Linux

Introduction

NFS (Network File Server) is used for sharing files between linux to linux, unix to linux and vice versa.

Package: nfs-utils
By Default Port: 2049
Configuration File: /etc/exports

Step 1: Install nfs package

First install nfs-utils package using following command:

# yum -y install nfs-utils

Step 2: Configuration

Edit file idmapd.conf and add the line:

# vi /etc/idmapd.conf
Domain = tecdistro-server

Insert the folder/directory along with network that you want to share it with other unix/linux machines:

# mkdir /data
# chmod a+rwx /data
# vi /etc/exports
/data *(ro)
/var 192.168.0.0/24(ro)
/home 172.0.0.0/24(rw,no_root_squash)

Step 3: Start Services

Start the services rpcbind, nfslock and nfs.

# service rpcbind start
Starting rpcbind:                         [  OK  ]
# service nfslock start
Starting NFS statd:                       [  OK  ]
# service nfs start
Starting NFS services:                    [  OK  ]
Starting NFS mountd:                      [  OK  ]
Starting NFS daemon:                      [  OK  ]
Starting RPC idmapd:                      [  OK  ]

OR
The following command is equivalent to nfs restart

# exports -ar

Run the services at startup/booting time.

# chkconfig rpcbind on
# chkconfig nfslock on
# chkconfig nfs on

Step 4: On Client Side

Now at the NFS client end, we need to mount that directory in our server to access it locally. To do so, first we need to find out that shares available on the remote server or NFS Server.

# showmount -e 192.168.0.10

Export list for 192.168.0.10:
/data 192.168.0.10

Above command shows that a directory named “data” is available at “192.168.0.10” to share with your server.
To mount the directory from NFS server to client server use the following command:

# mount 192.168.0.10:/var /local

How to Compress file/folder in Linux

Introduction

A backup, or the process of backing up, refers to the copying and archiving of computer data so it may be used to restore the original after a data loss event. The verb form is to back up in two words, whereas the noun is backup. Backups have two distinct purposes.

  • The primary purpose is to recover data after its loss, be it by data deletion or corruption.
  • Data loss can be a common experience of computer users.

Following are the methods through which we can compress the file and folders.

1) ZIP a file/folder

#zip file.zip file1 file2
#zip file.zip dir1
#zip -option file.zip dir1

How to zip a file with excluding file/folder

zip -r conference_01-01-2015_14-30.zip /var/www/conference/* -x home_backup/

2) TAR a file/folder

tar -cvf /backup/etc.tar /etc/*
tar -cvf /backup/etc.tar

3) GZIP a file/folder

gzip is the preferred compression tool for Linux. To compress the tar file using gzip, following is the command:

gzip etc.tar

To decompress the tar file using gzip, following is the command:

gzip -d etc.tar.gz

4) BZIP2 a file/folder

There is also another tool that is rapidly gaining acceptance in the Linux world: bzip2. This is supposed to become the official way of doing it in the near future, so it may be a good idea to get to know ‘bzip2’
To compress the tar file using bzip2, following is the command:

bzip2 etc.tar

To decompress the tar file using bzip2, following is the command:

bzip2 -d etc.tar.bz2

File/Folder Permissions in Linux

Introduction

Linux has inherited from UNIX the concept of ownerships and permissions for files. When applying permissions to directories on Linux, the permission bits have different meanings than on regular files.

  • The write bit allows the affected user to create, rename, or delete files within the directory, and modify the directory’s attributes
  • The read bit allows the affected user to list the files within the directory
  • The execute bit allows the affected user to enter the directory, and access files and directories inside
  • The sticky bit states that files and directories within that directory may only be deleted or renamed by their owner (or root)

Following are the useful commands for modifying file permissions and ownership:

  • chmod – modify file access rights
  • su – temporarily become the superuser
  • chown – change file ownership
  • chgrp – change a file’s group ownership

The Permission Groups used are:

  • User (u): The owner of file
  • Group (g): Other user who are in group (to access files)
  • Other (o): Everyone else

Octal numbers and permissions

There are three types of modes in file system i.e

  • Read (r) – 4
  • Write (w) – 2
  • Execute (x) – 1

For Example if we want to change the file permission to 777, 666, 700

  • rwx rwx rwx = 111 111 111 = 777
  • rw- rw- rw- = 110 110 110 = 666
  • rwx — — = 111 000 000 = 700

Change Ownership of Directory/File

To change the ownership of any directory or file use the  “chown” command:

# chown wheel:wheel filename

Change Permission of Directory/File

To setup a file readable by anyone and writable by the owner only:

# chmod 644 file

To setup a file readable/executable by everyone and writable by the owner only:

# chmod 755 file

Note: By default the file permission of file in linux is 644 and 755 for folder.

Recursively Change:

We can change file permissions recursively with the following command:
For Directories:

# find /path/to/your/wordpress/install/ -type d -exec chmod 755 {} ;

For Files:

find /path/to/your/wordpress/install/ -type f -exec chmod 644 {} ;

How to Zip a file/folder

Zip a Single File

To make a zip of single file, execute the below command:

#zip file.zip file1 file2

Zip Multiple Files

To make a zip of multiple files, execute the below command:

#zip file.zip file1 file2

Zip Single Folder

To make a zip of folder/directory, execute the below command:

#zip file.zip dir1

To make a optional zip of folder/directory, execute the below command:

#zip -option file.zip dir1