Category Archives: Unix

  • 1

Unix useful commands

Sometime we need a user who can do everything in our server as root does. So we may do the following:

  1. Create a new user with the same privileges as root
  2. Grant same same privileges to existing user as root

Case 1: Lets say we need to add a new user and grant him root privileges :

Use the following commands to create the new user temp, grand him the same privileges as root and set him a password :

[root@m1 ~]# useradd -ou 0 -g 0 temp

[root@m1 ~]# passwd temp

Changing password for user temp.

New password:

BAD PASSWORD: it is based on a dictionary word

BAD PASSWORD: is too simple

Retype new password:

passwd: all authentication tokens updated successfully.

We’ve just created the user temp, with UID 0 and GID 0, so he is in the same group and has the same permissions as root.

Case 2: Grant ROOT Privileges to an Existing USER: 
Perhaps you already have some user temp and you would like to give root permissions to a normal user.

[root@m1 ~]# grep temp1 /etc/passwd

temp1:x:1006:1006::/home/temp1:/bin/bash

Solu 1:

Edit /etc/passwd file and grant root permissions to the user temp1 by changing User and Group IDs to UID 0 and GID 0. 

Solu 2: Create a group and assign this existing user to that group. Also grant that group to sudo access.

[root@m1 ~]# groupadd test

[root@m1 ~]# usermod -g test temp1

[temp2@m1 ~]$ id temp1

uid=1006(temp1) gid=1007(test) groups=1007(test)

Edit /etc/sudoers file and add %test ALL=(ALL)       NOPASSWD: ALL line to file. 

[root@m1 ~]# grep -C4 test /etc/sudoers

# %wheel ALL=(ALL) ALL

## Same thing without a password

%wheel ALL=(ALL) NOPASSWD: ALL

%test ALL=(ALL)       NOPASSWD: ALL

[root@m1 ~]# su temp1

[temp1@m1 ~]$ sudo su – hdfs

[hdfs@m1 ~]$ exit

logout

[temp1@m1 ~]$ sudo su – root

[root@m1 ~]# exit

logout

Delete a USER Account with UID 0 : You won’t be able to delete second root user with another UID 0 using userdel command.
[root@m1 ~]# userdel temp
userdel: user temp is currently used by process 1

To delete user temp with UID 0, open /etc/passwd file and change temp’s UID.
[root@m1 ~]# vi /etc/passwd
[root@m1 ~]# id temp
temp:x:1111:0::/home/temp:/bin/sh

Now, you’ll be able to delete user temp with userdel command :
[root@m1 ~]# userdel temp
[root@m1 ~]# id temp

id: temp: No such user

 

How to make sure /etc/resolv.conf Never Get Updated By DHCP Client in centos 6 :

I using GNU/Linux with the Internet Systems Consortium DHCP Client. It also updates my /etc/resolv.conf file each time my laptop connects to different network or after restart machine. I would like to keep my existing nameservers. How do I skip /etc/resolv.conf update on a Linux based system?

The DHCP protocol allows a host to contact a central server which maintains a list of IP addresses which may be assigned on one or more subnets. This protocol reduces system administration workload, allowing devices to be added to the network with little or no manual configuration. There are various method to fix this issue but I would prefer to use the following one.

We have to modify our interface configuration file such as /etc/sysconfig/network-scripts/ifcfg-eth0 file and append the following option:

 

[root@m1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0

TYPE=Ethernet

ONBOOT=yes

NM_CONTROLLED=yes

BOOTPROTO=dhcp

HWADDR=08:00:27:90:1E:98

DEFROUTE=yes

PEERDNS=NO ## change it to No from Yes and the following DNS accordingly. 

DNS1=192.168.56.104

DNS2=168.244.212.13

DNS3=168.244.217.13

PEERROUTES=yes

IPV4_FAILURE_FATAL=yes

IPV6INIT=no

NAME=”System eth0″

Save and close the file. Where,

1. PEERDNS=yes|no – Modify /etc/resolv.conf if peer uses msdns extension (PPP only) or DNS{1,2} are set, or if using dhclient. default to “yes”.

2. DNS{1,2}=<ip address> – Provide DNS addresses that are dropped into the resolv.conf file if PEERDNS is not set to “no”.

 

I hope this will help you, please feel free to give your valuable suggestion or feedback.


  • 1

Enable GUI for Centos 6 on top of command line

If you have installed CentOS 6.5, and you just have a terminal with a black background and you want to enable GUI then thsi article is for you to get it done.

Desktop environment is not necessary for Server usage, though. But Sometimes installation or using an application requires Desktop Environment, then build Desktop Environment as follows.

1 .Install GNOME Desktop Environment on here.

[root@m1 ~]# yum -y groupinstall “X Window System”

Loaded plugins: fastestmirror

Setting up Group Process

Loading mirror speeds from cached hostfile

* base: mirrors.centos.webair.com

* extras: mirror.pac-12.org

* updates: bay.uchicago.edu

base/group_gz                                                                                                         | 226 kB     00:06     

Resolving Dependencies

There are unfinished transactions remaining. You might consider running yum-complete-transaction first to finish them.

The program yum-complete-transaction is found in the yum-utils package.

–> Running transaction check

—> Package firstboot.x86_64 0:1.110.15-4.el6 will be installed

————————-

————————

Complete!

2. Install Desktop

[root@m1 ~]# yum -y groupinstall “Desktop”

Loaded plugins: fastestmirror

Setting up Group Process

Loading mirror speeds from cached hostfile

* base: mirror.atlanticmetro.net

* extras: centos.chi.host-engine.com

* updates: centos.chi.host-engine.com

Package notification-daemon-0.5.0-1.el6.x86_64 already installed and latest version

Package metacity-2.28.0-23.el6.x86_64 already installed and latest version

Package yelp-2.28.1-17.el6_3.x86_64 already installed and latest version

Resolving Dependencies

There are unfinished transactions remaining. You might consider running yum-complete-transaction first to finish them.

The program yum-complete-transaction is found in the yum-utils package.

–> Running transaction check

—> Package NetworkManager.x86_64 1:0.8.1-107.el6 will be installed

Complete!

3. Install General Purpose Desktop

[root@m1 ~]# yum -y groupinstall “General Purpose Desktop”

Loaded plugins: fastestmirror, refresh-packagekit

Setting up Group Process

Loading mirror speeds from cached hostfile

* base: mirror.cs.pitt.edu

* extras: mirrors.kernel.org

* updates: centos.mirrors.wvstateu.edu

HDP-2.5                                                                                                               | 2.9 kB     00:00     

HDP-2.5.3.0                                                                                                           | 2.9 kB     00:00     

HDP-UTILS-1.1.0.21                                                                                                    | 2.9 kB     00:00     

HDP-UTILS-2.5.3.0                                                                                                     | 2.9 kB     00:00     

Updates-ambari-2.4.1.0                                                                                                | 2.9 kB     00:00     

base                                                                                                                  | 3.7 kB     00:00     

extras                                                                                                                | 3.4 kB     00:00     

mysql-connectors-community                                                                                            | 2.5 kB     00:00     

mysql-tools-community                                                                                                 | 2.5 kB     00:00     

mysql56-community                                                                                                     | 2.5 kB     00:00     

updates                                                                                                               | 3.4 kB     00:00     

Package gnome-themes-2.28.1-7.el6.noarch already installed and latest version

4. Input a command like below after finishing installation of new packages.

$startx

or

5. Run following command to have your GUI on your system. 

[root@m1 ~]# init 5

Screen Shot 2017-02-21 at 7.58.29 PM