Unix useful commands
Category : Unix
Sometime we need a user who can do everything in our server as root does. So we may do the following:
- Create a new user with the same privileges as root
- 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.