Adding user to SUDOERS in CentOS 6, 6.4, 6.5, RHEL6, RHEL 6.3, 6.4

Here we can see how to add the sudo in Centos, In Ubuntu by Default sudo will be enabled, But in Centos and RHEL there is not sudo enabled by deafult, we can see here how to access the root privilage from other user by adding the user to Sudo Group.

Switch to Root user using su

$ su

Edit the Sudoer’s file using vim

# vim /etc/sudoers

 

Go to Line 98, Look for Below command

## Allow root to run any commands anywhere
root     ALL=(ALL)     ALL

 

add this line, replacing [USERNAME] with your Respective username)

Syntax:

[USERNAME]     ALL=(ALL)     ALL

 

Here i have added a user named linuxmental to sudoer below

## Allow root to run any commands anywhere
root     ALL=(ALL)     ALL
linuxmental	ALL=(ALL)     ALL

Save the file and Exit using wq!

Then switch to normal user linuxmental and execute some commands with sudoers privilage.

Output:

[linuxmental@centos ~]$ sudo /etc/init.d/network restart
Shutting down interface eth0:[  OK  ]Shutting down loopback interface:[  OK  ]Bringing up loopback interface:[  OK  ]Bringing up interface eth0:[  OK  ]

 

That’s it …

Advertisements

vps centos check cpu and memery usage

For memery use:

free -m

You will see an output like this:

total       used       free     shared    buffers     cached

Mem:           512        462         49          0         46        127

-/+ buffers/cache:        287        224

Swap:         2047          0       2047

The important figure to look at is the “used” number in the “buffers/cache” row. This will tell you how much memory your processes are currently using. Memory allocation errors will occur if this number is higher than the total amount of memory and swap space. To see how much RAM is free, check the “free” column in the “buffers/cache” row.

for running process check use:

ps aux

The output will look like this:
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.1  10368   632 ?        Ss   Jan07   0:00 init [3]
root         2  0.0  0.0      0     0 ?        S<   Jan07   0:00 [migration/0]
root         3  0.0  0.0      0     0 ?        SN   Jan07   0:00 [ksoftirqd/0]
One of the benefits of a VPS is that, in the case of a memory shortage, you can upgrade RAM on-the-fly with little (Xen) to no (OpenVZ) downtime. Open a support ticket, or find us on live chat, if you need an upgrade!
For active listening port:
netstat -ntplau

Creating links to files and directories in unix centos vps

Creating a link to a directory

It is often useful to change to another directory without typing its full pathname: symbolic links provide a useful shortcut to do this. A symbolic link differs from a hard link. It is a small file that contains a reference (by name) to a directory or file that already exists. Unlike normal links, symbolic links can cross filesystems and link to directories. (They are used extensively by the system.) Also unlike normal links, symbolic links are separate files; they cease to work if the file they point to is deleted or renamed, or if they are moved.

Many of the files found in /bin/lib, and /usr are actually symbolic links that point to files (of the same name) stored below /var/opt. The directories these files are located in are called “storage sections”. Storage sections are used because they make it easier to install system upgrades. Software subsystems (such as UUCP) consist of many files, which may be installed in several directories. However, all the files in a subsystem belong to a single storage section. By overwriting the contents of the (single) storage section directory, all the files in the subsystem can be updated simultaneously.

Symbolic links are identified in a directory listing by a “->”, as follows:

   $ l
   drw-r--r--  1 johnd  unixdoc     29  Feb 27 15:56 mydata -> /u/work
   group/tasks/project/01

You can obtain a directory listing without symbolic links visible in it by specifying the -L (logical) option. This makes ls (or l, or any related program) list the directory, replacing the information about each symbolic link with the details for the file pointed to by the link:

   $ l -L
   drw-r--r--  1 johnd  unixdoc   10297  Feb 27 15:56 mydata

To create a symbolic link, use the ln -s option, as follows:

ln -s directory symbolic_link

For example, suppose you work in /u/workgrp/tasks/projects and your home directory is /u/me. Your normal command to work on a file would be the following:

   $ cd /u/workgrp/tasks/projects

To reduce the typing required, enter the following command:

   $ ln -s /u/workgrp/tasks/projects mydata

This command creates a symbolic link called mydata in your current directory. From now on, mydata and /u/workgrp/tasks/projects refer to the same location, and you can relocate to /u/workgrp/tasks/projects by typing cd mydata instead of typing in the full pathname.

You must have write permission on a directory before you can create a link that involves that directory or a file in that directory.

add tomcat to auto start in centos VPS

This article assumes that you have already installed the Apache Tomcat Server on your Linux Centos machine. If you need help with your with Apache Tomcat Setup then please click on the Link below.

 

Step 1: Create a file named tomcat6 in your /etc/init.d directory

$ cd /etc/init.d
$ gedit tomcat6 

If this file is created in windows, make sure the file be converted to UNIX format.  Otherwise,  following would happen:

/bin/bash^M: bad interpreter: No such file or directory

Below is one way to do the conversion in Notepad++

Step 2: Copy the following script and save the file

#!/bin/bash
# chkconfig: 2345 80 20
# Description: Tomcat Server basic start/shutdown script
# /etc/init.d/tomcat6 -- startup script for the Tomcat 6 servlet engine

TOMCAT_HOME=/usr/local/apache-tomcat-6.0.35/bin START_TOMCAT=/usr/local/apache-tomcat-6.0.35/bin/startup.sh STOP_TOMCAT=/usr/local/apache-tomcat-6.0.35/bin/shutdown.sh

start() {
 echo -n "Starting tomcat6: "
 cd $TOMCAT_HOME
 ${START_TOMCAT}
 echo "done."
}

stop() {
 echo -n "Shutting down tomcat6: "
 cd $TOMCAT_HOME
 ${STOP_TOMCAT}
 echo "done."
}

case "$1" in

start)
 start
 ;;

stop)
 stop
 ;;

restart)
 stop
 sleep 10
 start
 ;;

*)
 echo "Usage: $0 {start|stop|restart}"

esac
exit 0

Change the settings for the chkconfig based on your requirements. In a scenario where Apache Web server is in the front of Tomcat server with MySQL database usually the startup sequence should be MySQL then Tomcat and Apache Web Server in last. Also make sure you change the TOMCAT_HOME, START_TOMCAT and STOP_TOMCAT variables based on your Tomcat Install.

Step 3: Update the file permissions to make it executable by any user

$ chmod 755 tomcat6

Step 4: Make sure you have chkconfig command installed

$ chkconfig --help

otherwise just install it
$ sudo apt-get install chkconfig

 

Step 5: Run chkconfig command to add the script to the startup services

$ chkconfig --add tomcat6

(double dash before add )

Basically the chkconfig command automatically adds the symbolic links for starting and stopping the service based on the paramaters passed to it. Here is the list of links created from the above link. You can run the find command to check.

关于 chkconfig
$ find . -name “*tomcat6”

Response from the above command …
./rc.d/init.d/tomcat6
./rc.d/rc4.d/S80tomcat6
./rc.d/rc3.d/S80tomcat6
./rc.d/rc6.d/K20tomcat6
./rc.d/rc5.d/S80tomcat6
./rc.d/rc2.d/S80tomcat6
./rc.d/rc0.d/K20tomcat6
./rc.d/rc1.d/K20tomcat6

Step 6: Make sure scripts got added to the startup services

Type the following command on the Terminal

$ chkconfig --list tomcat6 

   (double dash before list)
Response should be something like this
tomcat6         0:off   1:off   2:on    3:on    4:on    5:on    6:off
 

Step 7: Verify your service is working

To start the Tomcat server
$ service tomcat6 start
To stop the Tomcat server
$ service tomcat6 stop

open MySQL in CentOs and auto start

* To start mysql server:

/etc/init.d/mysqld start

* To stop mysql server:

/etc/init.d/mysqld stop

* To restart mysql server

 /etc/init.d/mysqld restart

Tip: Redhat Linux also supports service command, which can be use to start, restart, stop any service:

# service mysqld start
# service mysqld stop
# service mysqld restart

To make it auto start:
Use: sudo /sbin/chkconfig mysqld on

To Check: chkconfig --list

To stop a service from auto starting on boot


  • sudo /sbin/chkconfig mysqld off