Posts

Showing posts from 2013

Creating custom SSH welcome messages

Image
Login to your server as root via SSH. sudo vim /etc/motd Now type in the message you want everyone to see.  ######### Welcome to the Vishal's server #########
 ###         This is the webServer                               ###
 ###########################################
Save and Quit,
Logout of SSH then log back in, you will receive your new greeting! ...EnJoY... Vishal Vyas

Linux Network Bandwidth check Script.

Image
1.netpps.sh#!/bin/bash INTERVAL="1" # update interval in seconds if [ -z "$1" ]; then echo echo usage: $0 [network-interface] echo echo e.g. $0 eth0 echo echo shows packets-per-second exit fi IF=$1 while true do R1=`cat /sys/class/net/$1/statistics/rx_packets` T1=`cat /sys/class/net/$1/statistics/tx_packets` sleep $INTERVAL R2=`cat /sys/class/net/$1/statistics/rx_packets` T2=`cat /sys/class/net/$1/statistics/tx_packets` TXPPS=`expr $T2 - $T1` RXPPS=`expr $R2 - $R1` echo "TX $1: $TXPPS pkts/s RX $1: $RXPPS pkts/s" done Measure Network Bandwidth on an Interface2.netpps.sh#!/bin/bash INTERVAL="1" # update interval in seconds if [ -z "$1" ]; then echo echo usage: $0 [network-interface] echo echo e.g. $0 eth0 echo exit fi IF=$1 while true …

Block certain file extensions on samba linux

Block certain file extensions on samba linux
If you are using Samba server in your organization and want to restrict some file types to upload in shared directory. then you can use veto file to block certain file type in samba, You can restrict to upload mp3, mp3, exe, or any file types using it. Here i have shared a directory name "vishal" and block some file extentions using veto file in samba. Open samba config file and added veto file to last line of your shared block. $ vim /etc/samba/smb.conf [Vishal] comment = vishalvyas Path = /home/vishal public = yes writable = yes browseable = yes read only = no valid user = vishal create mask = 0775 Veto files = /*.exe/*.com/*.dll/*.bat/*.vbs/*.tmp/*.mp3/*.avi/*.mp4/*.wmv/*.wma/

How to increase swap size in linux

Image
Swap is a type of filesystem and is a virtual memory. Whenever your RAM is full, your operating system will look for further memory in your swap space. For this reason, you reserve some part of the hard disk to create a swap partition.


Identifying Current Swap Space Usage:

root@vishal-desktop:/# cat /proc/swaps
Filename                                Type            Size    Used    Priority
/dev/sda7                               partition       1951740 4       -1

Alternatively, use the swapon command:

root@vishal-desktop:/# swapon -s
Filename                                Type            Size    Used    Priority
/dev/sda7                               partition       1951740 4       -1


Finally, the free command may also be used:

root@vishal-desktop:/# free
             total       used       free     shared    buffers     cached
Mem:        895112     721656     173456          0      36592     310156
-/+ buffers/cache:     374908     520204
Swap:      1952736          4    1952732



root@vish…

Monitoring User Activity with psacct On Linux

Image
One of the big advantages of using psacct on your server is that it provides excellent logging for activities of applications and users.





Installation :-

for Redhat, Fedora, CentOs

yum install psacct
service psacct start

For Ubuntu Debian

apt-get install acct
service acct start



How to use psacct :

The connect time in hours is based on logins and logouts. 

root@Vishalvyas:~#  ac -p
        vishal                        9.12
        Ashish                      20.60
        Vipul                        15.80
        Anil                          17.33
        Akshay                     10.92
        pritesh                      4.10
        chirag                       8.75
        total                         168.95

Which user has executed what command on system :

root@Vishalvyas:~# lastcomm vishal

Process        Flag    Username  Terminal    Time

vim                          X vishal        pts/2         0.01 secs Tue Mar  5 10:16
su               S           vishal            pts/2         0.00 secs Tu…

VIM editor commands and examples - Linux

Image
VIM An Advanced Text Editor:-

=> Newer Virsion of VI, the standard Unix text editor

=> gvim :         Graphical Version of vim


ADVANTAGES OF VIM :-

SPEED            : Do more with fewer keystrokes
Simplicity        : No dependence on mouse/GUI
Availability      : Included with most Unix-like OSes

DISADVANTAGES :-
Difficulty         : Stteper learning curve than simpler editors

Three Main Mode :-
Command Mode     : Move cursor, cut/paste text, change mode
Insert Mode            : Modify text
Ex Mode                 : Save, quit, etc

'Esc' key is used to exits current mode.

'EscEsc' always returns to command mode.


=> vim abc.txt        : can edit the text file if existing or not
=> vim /etc/passwd
=> vim /tmp/file


INSERT MODE :-

   : begins insert end of line
: Append to end of line
  : Insert at beginning of line
     (small)    o    insert new a line (below of current line)
     (caps)    O    insert new line ( above of current line )


EX MODE with ( : ) :-

:w       : wr…

Browsing linux filesystem

Basic linux commands

Image
==>>>Command










- date: to see the date and time - date 112503451982 : month,date,hour,minut,year - cal: to see the calendar - cal 2010: to see the calendar of 2010 - cal 5 2010: display the calendar of May 2010 - clear: to clear the screen - ls: to see the list of dir and file - useradd vishal: to create user with name 'vishal' - passwd vishal: to set & also change password of user 'vishal' - passwd: to root only
- passwd -d vishal: create user without password - usermod -l n-name o-name: to rename user - usermod -g group user: to add user in group - useradd -n vishal: create user without duplicate directory - userdel vishal: to delet user - userdel -r vishal: Delet user with their directory - rm -rf directory: forcefuly remove directory
- groups vishal: to see membarship of user - vi /etc/passwd: see user directory - groupadd sels: create group