Wednesday, May 20, 2015

System Administration Best Practices

System Administration Best Practices


Linux distributions have three branches

SLS :


The Softlanding Linux System (SLS) distribution, which evolved into the Slackware
distribution, is one of the oldest

RPM

The Red Hat Package Manager (RPM) was developed by Red Hat in order to
provide some structure for software management.

DPKG or DEB


The Debian Packaging System (DPKG/DEB) was developed about the same time
as the RPM, and has the same features, although they are implemented differently.


Summary


Debian is an extremely stable Linux distribution that includes a great variety of
software that runs in many different environments and on many different CPU
architectures. It is free, in the spirit of the Free Software Foundation's definition,
and thus may be run freely on as many systems as an administrator desires, without
limit or licensing fees. It may be freely copied, modified, and re-distributed. Debian
is available from many official Debian servers and mirrors, and it is well supported
by an official and well-defined, albeit all-volunteer organization, which provides
support via many channels. Paid installation media and support are also available
from many third parties.

Filesystem 

Types

Selecting a filesystem format is the next major choice before installing Debian. The
supported formats that are appropriate for a Linux installation include ext2, ext3,
ext4, JFS, XFS, ReiserFS, and Btrfs. The first three are actually progressive versions of
the extended filesystem (ext) developed specifically for Linux.

ext2, ext3, and ext4

The ext filesystem was originally developed to overcome the limitations of the
MINIX filesystem.
MINIX was Linus Torvalds' inspiration for Linux.
The second extended filesystem (ext2) improved upon it, while the third extended
filesystem (ext3) added journaling, as well as performance improvements. The fourth
extended filesystem (ext4) added additional features and performance improvements.
The ability to disable journaling is one reason ext2
was sometimes used over ext3 for flash drives in
order to reduce the write cycles.

Journaled File System


Developed by IBM for its Unix-like AIX operating system, and offered as an
alternative to the ext and ext2 filesystems via release under the GPL, Journaled File
System (JFS) is one of the alternatives to the current ext4. It uses fewer resources,
while remaining quite stable and resilient. It includes many features of Btrfs, and
is a good choice when CPU power is limited, or with database systems that require
synchronous writes to survive hardware failures.

Saturday, May 16, 2015

Authentication token manipulation error

  Authentication token manipulation error


[root@sysadmin Desktop]# pwconv
[root@sysadmin Desktop]# passwd demo
Changing password for user demo.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.

Friday, May 15, 2015

Set Up a Virtual Host


1)Root login :-#ssh root@192.168.100.251
2)Create new user:- #adduser demo1
3)Change Password:- #passwd demo1
4)Change Root privileges:- visudo
       
        root    ALL=(ALL)       ALL
     demo1   ALL=(ALL)       ALL


5)su demo1 (Switch user)
6)sudo yum install httpd
7)sudo mkdir -p /var/www/server.lan/public_html
8)sudo chown -R apache:apache /var/www/server.lan/public_html
9)sudo chmod -R 777 /var/www
10)  create a new file called index.html within our configurations directory.

     sudo vi /var/www/server.lan/public_html/index.html

11)add below text to the file index.html

<html>
  <head>
    <title>www.server.lan</title>
  </head>
  <body>
    <h1>Success: You Have Set Up a Virtual Host</h1>
  </body>
</html>


----------------Turn on virtual Host:-

 12)    sudo vi /etc/httpd/conf/httpd.conf

   #Listen 12.34.56.78:80
   #////add hash on Listen 80 & add ip Listen 192.168.100.251:80
   # Listen 80
 Listen 192.168.100.251:80 

NameVirtualHost *:80
#
# NOTE: NameVirtualHost cannot be used without a port specifier
# (e.g. :80) if mod_ssl is being used, due to the nature of the
# SSL protocol.
#   

#   
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
#
<VirtualHost *:80>
     ServerAdmin webmaster@server.lan
     DocumentRoot /var/www/server.lan/public_html
     ServerName www.server.lan
     ServerAlias server.lan
   #  ErrorLog /var/www/server.lan/error.log
    # CustomLog /var/www/server.lan/requests.log
</VirtualHost>

13)   #sudo systemctl stop httpd.service

14)   #sudo /etc/init.d/httpd start

15) sudo vim /etc/hosts

# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       localhost

#Virtual Hosts
192.168.100.251    www.server.lan

16)check result

curl -I http://192.168.100.251

Wednesday, May 13, 2015

Install Samba to build a File Server

Install and Configure Samba.



  smbclient -L //localhost
1)
  mkdir /sambashare
  chmod 777 /sambashare
  ls -ltr /
  cd /sambashare/
   touch testfile1
   touch testfile2
  useradd lisa

2) 
  yum -y install samba samba-client
 
  cd /etc/samba/
 
  cp smb.conf smb.conf.backup

3)
  vim smb.conf
    workgroup = sambagroup
//copy last section para as it & modify it
        [sambashare]
       comment = my share
       path = /sambashare
       public = yes
       writable = yes
       write list = +users
4)
  service smb start

  service smb status
 
  smbpasswd -a lisa

5) 

  ls -ltr /sambashare/
  
  ls -Zd /sambashare/

6)  setenforce 0

how to test samba work
   smbclient -L //192.168.100.251 -U lisa
 
7) 
  mount  -o username=lisa //192.168.100.251/sambashare/ /mnt
   cd /mnt
   ls

8) access from windows

   \\192.168.100.251

///////////////////////////////////////////////////////////////////

  testparm



//////////////////////////////////////////////////////////////////
  
  [root@mydemovm home]# systemctl stop firewalld
[root@mydemovm home]# systemctl disable firewalld
 



////////////////////////////////////////////////////////////////////

 umount -l /mnt

 mount  -o username=lisa //192.168.100.251/sambashare/ /mnt

 umount -f /mnt

 ls -Zd /sambashare

  smbclient -L //192.168.100.251 -U lisa

 yum install cifs-utils -y

Sunday, May 10, 2015

Own Git server like github

Gitorious is an open source web interface to git that you can run on your own server, much like github:

http://getgitorious.com/

Update:
http://gitlab.org/ is another alternative now as well.

Update 2:
Gitorious has now joined with GitLab

The commercial service by GitHub starts at US$ 25 a month, ranging up to US$ 200 for the Platinum service, whereas Gitorious costs at least US$ 99 for your own sub-domain.


Fedora and Ubuntu include the two programs in their package repositories, which makes the install very easy.


 The basic requirements for setting up a Git server are a directory for the configuration and the repositories, a user account, and SSH keys needed to handle authentication. Access to Git repositories always relies on SSH, which means the Git servers don’t need a separate port. 




Thursday, May 7, 2015

Soft links hard links


1. What are links in Unix?
    A link in UNIX is a pointer to a file. Like pointers in any programming languages, links in UNIX are pointers pointing to a file or a directory . Creating links is a kind of shortcuts to access a file. The two different types of links in UNIX are:
  • Soft Links or Symbolic Links
  • Hard links

2. How to create Soft links and hard links? And how do we access them?
     Say, you have a file named "file1" with the following contents:
$ cat file1
welcome
.   To create a hard link of file1:
$ ln file1 file2
   To create a soft link of file1:
$ ln -s file1 file3 
    Once the links are created, the linked files contain the same content as of the original file. See below
$ cat file2
welcome
$ cat file3
welcome
Note: Soft links can be created on non-existent files as well.

3. "file2" and "file3" being the linked files, can I say which is a soft link & which is hard link?
   Yes. When you do the listing of the files with "-li" option:
$ ls -li
total 20
9962464 -rw-r--r-- 2 guru users 8 Mar  9  file1
9962464 -rw-r--r-- 2 guru users 8 Mar  9  file2
9962471 lrwxrwxrwx 1 guru users 5 Mar  9  file3 -> file1
   If you notice file3, it shows "->" towards file1. This indicates file3 is a soft-link of file1.  In case of file2, if you notice the inode numbers of file1 and file2, they are the same. Same inode number indicates file1 and file2 are hardlinks. Also note, the link count of these files is 2.

4. file1 and file2 are of the same size. In case of the file "file3", the file size is being shown as 5. How is it 5?
      The file size of a soft linked file is the length of the filename of the original file. In this case, the original file "file1" is of length 5. In a soft linked file, the location where the file content is to be stored, the file name of the original file gets stored, and hence the file size is so.

5. file1 and file2 are hardlinks? Can we say which is the original file and which is the hard-linked file?
    No. We cannot say which is the original file and which one was the hard-linked file. Once a hard-link is created, it is like 2 files pointing to the same location. In fact, once a hard link is created on a file, using the term 'original file' is actually incorrect.

6. Will deleting the file "file1" make "file2" and "file3" inaccessible?
   On deleting the file "file1", the soft linked file "file3" will become inaccessible. However, the hard linked file "file2" can still be accessed. - See more at: http://www.theunixschool.com/2012/03/soft-links-hard-links-all-about-inodes.html#sthash.JVsIPdJ1.dpuf
What are links in Unix?
    A link in UNIX is a pointer to a file. Like pointers in any programming languages, links in UNIX are pointers pointing to a file or a directory . Creating links is a kind of shortcuts to access a file. The two different types of links in UNIX are:
  • Soft Links or Symbolic Links
  • Hard links

2. How to create Soft links and hard links? And how do we access them?
     Say, you have a file named "file1" with the following contents:
$ cat file1
welcome
.   To create a hard link of file1:
$ ln file1 file2
   To create a soft link of file1:
$ ln -s file1 file3 
    Once the links are created, the linked files contain the same content as of the original file. See below
$ cat file2
welcome
$ cat file3
welcome
Note: Soft links can be created on non-existent files as well.

3. "file2" and "file3" being the linked files, can I say which is a soft link & which is hard link?
   Yes. When you do the listing of the files with "-li" option:
$ ls -li
total 20
9962464 -rw-r--r-- 2 guru users 8 Mar  9  file1
9962464 -rw-r--r-- 2 guru users 8 Mar  9  file2
9962471 lrwxrwxrwx 1 guru users 5 Mar  9  file3 -> file1
   If you notice file3, it shows "->" towards file1. This indicates file3 is a soft-link of file1.  In case of file2, if you notice the inode numbers of file1 and file2, they are the same. Same inode number indicates file1 and file2 are hardlinks. Also note, the link count of these files is 2.

4. file1 and file2 are of the same size. In case of the file "file3", the file size is being shown as 5. How is it 5?
      The file size of a soft linked file is the length of the filename of the original file. In this case, the original file "file1" is of length 5. In a soft linked file, the location where the file content is to be stored, the file name of the original file gets stored, and hence the file size is so.

5. file1 and file2 are hardlinks? Can we say which is the original file and which is the hard-linked file?
    No. We cannot say which is the original file and which one was the hard-linked file. Once a hard-link is created, it is like 2 files pointing to the same location. In fact, once a hard link is created on a file, using the term 'original file' is actually incorrect.

6. Will deleting the file "file1" make "file2" and "file3" inaccessible?
   On deleting the file "file1", the soft linked file "file3" will become inaccessible. However, the hard linked file "file2" can still be accessed. - See more at: http://www.theunixschool.com/2012/03/soft-links-hard-links-all-about-inodes.html#sthash.JVsIPdJ1.dpuf

   If you notice file3, it shows "->" towards file1. This indicates file3 is a soft-link of file1.  In case of file2, if you notice the inode numbers of file1 and file2, they are the same. Same inode number indicates file1 and file2 are hardlinks. Also note, the link count of these files is 2.

4. file1 and file2 are of the same size. In case of the file "file3", the file size is being shown as 5. How is it 5?
      The file size of a soft linked file is the length of the filename of the original file. In this case, the original file "file1" is of length 5. In a soft linked file, the location where the file content is to be stored, the file name of the original file gets stored, and hence the file size is so.

5. file1 and file2 are hardlinks? Can we say which is the original file and which is the hard-linked file?
    No. We cannot say which is the original file and which one was the hard-linked file. Once a hard-link is created, it is like 2 files pointing to the same location. In fact, once a hard link is created on a file, using the term 'original file' is actually incorrect.

6. Will deleting the file "file1" make "file2" and "file3" inaccessible?
   On deleting the file "file1", the soft linked file "file3" will become inaccessible. However, the hard linked file "file2" can still be accessed. - See more at: http://www.theunixschool.com/2012/03/soft-links-hard-links-all-about-inodes.html#sthash.JVsIPdJ1.dp
http://www.theunixschool.com/2012/03/soft-links-hard-links-all-about-inodes.html

How to find when my os was installed?

[root@sysadmin Desktop]# last |grep wtemp

[root@sysadmin Desktop]# last

 [root@sysadmin Desktop]# lsb_release -a
LSB Version:    :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch
Distributor ID:    CentOS
Description:    CentOS Linux release 7.1.1503 (Core)
Release:    7.1.1503
Codename:    Core

Linux video link

CronTab in unix


Put a shell script in one of these folders: /etc/cron.daily, /etc/cron.hourly, /etc/cron.monthly or /etc/cron.weekly

If these are not enough for you you can add more specific tasks eg. twice a month or every 5 minutes or... go to the terminal and type:


crontab -e
this will open your personal crontab (cron configuration file), the first line in that file explains it all (don't you think)! In every line you can define one command to run, and the format is quite simple when you get the hang of it. So the structure is:


minute hour day-of-month month day-of-week command
 
For all the numbers you can use lists eg, 5,34,55 in the first field will mean run at 5 past 34 past and 55 past what ever hour is defined.

You can also use intervals, they are defined like this: */20 this example means every 20th and if in the minutes column this will be equivalent to 0,20,40
So to run a command every monday at 5:30 in afternoon:



30 17 * * 1 /path/to/command
 
or every 15 minutes

 
*/15 * * * * /path/to/command
 
Note that the day-of-week goes from 0-6 where 0 is sunday.


/////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////
CronTab real example

it execute script every 1 min
[root@sysadmin Desktop]# crontab -u root -e

*/1 * * * *  /bin/cp /root/Documents/dev.pem /root/Desktop/


it copy file from document to desktop



//////////////////////////////////////////////////////////////////////////////////

Alternate Hour or 3 Hourly Schedule

If you want something to run once every two hours, you will have to use the slash, "/", character in your field. The slash character is the "step" character. In the case of a two hourly schedule, your time component of your cron file will read:
0 */2 * * *
The second field, "*/2", means every alternate hour.
Similarly, if you want something to run every 3 hours, you can change that field to "*/3", and so on.

Run Level list linux

Table 9-1. Run level numbers
0Halt the system.
1Single-user mode (for special administration).
2Local Multiuser with Networking but without network service (like NFS)
3Full Multiuser with Networking
4Not Used
5Full Multiuser with Networking and X Windows(GUI)
6Reboot.

How to login without passwd in linux

1. Entering runlevel 1

Some Linux distribution, such as Ubuntu for instance, offer a specific boot menu entry where it is stated "Recovery Mode" or "Single-User Mode". If this is your case, selecting this menu entry will boot your machine into single user mode, you can carry on with the next part. If not, you might want to read this part.
Using GRUB, you can manually edit the proposed menu entry at boot time. To do so, when GRUB is presenting the menu list (you might need to press ESC first), follow those instructions:
  • use the arrows to select the boot entry you want to modify.
  • press e to edit the entry
  • use the arrows to go to kernel line
  • press e to edit this entry
  • at the end of the line add the word single
  • press ESC to go back to the parent menu
  • press b to boot this kernel
The kernel should be booting as usual (except for the graphical splash screen you might be used to), and you will finally get a root prompt (sh#).
Here we are, we have gained root access to the filesystem, let's finally change the password.

2. Changing root password

As root, changing password does not ask for your old password, therefore running the command:
# passwd
will prompt you for your new password and will ask you to confirm it to make sure there is no typo.
That's it, you can now reboot your box and gain root access again

Tar & Untar

[root@sysadmin onlinetest]# touch file.txt file2.txt
[root@sysadmin onlinetest]# tar cvf dest.tar file.txt file2.txt
file.txt
file2.txt
[root@sysadmin onlinetest]# tar cvf dest.tar myfolder/.
tar: myfolder/.: Cannot stat: No such file or directory
tar: Exiting with failure status due to previous errors
[root@sysadmin onlinetest]# mkdir myfolder
[root@sysadmin onlinetest]# touch ./myfolder/fileinfolder.txt
[root@sysadmin onlinetest]# tar cvf dest.tar myfolder/.
myfolder/./
myfolder/./fileinfolder.txt
[root@sysadmin onlinetest]# ls
dest.tar  file2.txt  file.txt  myfolder
[root@sysadmin onlinetest]# tar xvf dest.tar
myfolder/./
myfolder/./fileinfolder.txt
[root@sysadmin onlinetest]#

Cent OS vs RHEL OS


Cent os RHEL OS
Community Enterprise Linux Server Redhat Enterprise Linux Server
Run by community Run by redhat company
No need to pay for complete distribution If you want complete distribution pay for that.
Cent Not providing  certifications Redhat is providing certification

Basic linux Commands

[root@sysadmin ~]# uname -r
3.10.0-229.1.2.el7.x86_64
[root@sysadmin ~]# runlevel
N 5
[root@sysadmin ~]# who -r
         run-level 5  2015-05-07 10:41
[root@sysadmin ~]# users
root root
[root@sysadmin ~]# pwd
/root

[root@sysadmin ~]# uptime
 15:13:05 up  4:32,  2 users,  load average: 0.50, 0.69, 0.57
[root@sysadmin ~]# date
Thu May  7 15:13:19 IST 2015
[root@sysadmin ~]# tty
/dev/pts/0
[root@sysadmin ~]# umask
0022
[root@sysadmin ~]# who
root     :0           2015-05-07 10:44 (:0)
root     pts/0        2015-05-07 15:11 (:0)
[root@sysadmin ~]# whoami
root
[root@sysadmin ~]# logname
root
[root@sysadmin ~]# uname --n
sysadmin.myshala.lan
[root@sysadmin ~]# uname -n
sysadmin.myshala.lan
[root@sysadmin ~]# uname -p
x86_64
[root@sysadmin ~]# uname -m
x86_64
[root@sysadmin ~]# uname -s
Linux

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

[root@sysadmin ~]# pwd
/root
[root@sysadmin ~]# !!
pwd
/root
[root@sysadmin ~]# alias hname=hostname
[root@sysadmin ~]# hname
sysadmin.myshala.lan
[root@sysadmin ~]# alias -p
alias cp='cp -i'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias h='ls'
alias hname='hostname'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'
alias rvm-restart='rvm_reload_flag=1 source '\''/usr/local/rvm/scripts/rvm'\'''
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
[root@sysadmin ~]# alias help
bash: alias: help: not found
[root@sysadmin ~]# alias --help
bash: alias: --: invalid option
alias: usage: alias [-p] [name[=value] ... ]
[root@sysadmin ~]# unalias h

[root@sysadmin ~]# stat autel
stat: cannot stat ‘autel’: No such file or directory
[root@sysadmin ~]# groups
root
[root@sysadmin ~]#
 ////////////////////////////////////////////////////////////////////////////////////////////////


[root@sysadmin home]# dir
cen  cent  laike9m  mahesh  myshala  myshala.lan253  root  solution  test
[root@sysadmin home]# eject
eject: /dev/cdrom: not found mountpoint or device with the given name
[root@sysadmin home]# dirs
/home
[root@sysadmin home]# arch
x86_64
[root@sysadmin home]# !ar
arch
x86_64


//////////////////////////////////////////////////////////////////////////////////////////////
  

          netstat -r
          netstat -a
          netstat -nvlt

          netstat -nvlp
          netstat -nvlm

      

Good website to learn linux

Online simulator in Linux or Run linux command online