前言
在oracle用户编写一个shell,而其中某行代码需要执行root权限的命令,遂产生此文。
结论
1,sudo可以在非ROOT用户执行ROOT权限,其执行形式:
[oracle@seconary ~]$ sudo mount /dev/sdb1 /oradata
2,不配置SUDO相关配置文件/etc/sudoers,运行sudo会报oracle is not in the sudoers file. This incident will be reported.
3,在配置文件添加oracle ALL=(ALL) ALL,虽可以在非ROOT用户执行ROOT权限,但仍要输入ROOT密码
4,在配置文件添加oracle ALL=(ALL) NOPASSWD: ALL,不用输入ROOT密码,即可在非ROOT用户执行ROOT权限
5, 以上适用于redhat 5.4
6, 在suse 11上,仅首次运行sudo要输入密码,后面不用再输入密码
7,在suse 11,重启后同6,首次运行SUDO要输入密码,后面不用再输入密码
测试
[oracle@seconary ~]$ more /etc/redhat-release
Red Hat Enterprise Linux Server release 5.4 (Tikanga)
[oracle@seconary ~]$ sudo mount 10.0.0.39:/nfs_dir /nfs_client
oracle is not in the sudoers file. This incident will be reported.
[root@seconary ~]# cp /etc/sudoers /etc/sudoers.bak
[root@seconary ~]#
---添加如下内容
[root@seconary ~]# vi /etc/sudoers
oracle ALL=(ALL) ALL
[oracle@seconary ~]$ sudo mount 10.0.0.39:/nfs_dir /nfs_client
Password:
[oracle@seconary ~]$
---添加如下内容
oracle ALL=(ALL) NOPASSWD: ALL
---可以在ORACLE用户执行ROOT的MOUNT权限,且不用输入密码即可
[oracle@seconary ~]$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
130G 80G 44G 65% /
/dev/sda1 99M 13M 82M 13% /boot
tmpfs 2.0G 746M 1.3G 38% /dev/shm
/dev/sdc1 17G 14G 1.9G 89% /11204grid
/dev/sdc2 18G 17G 56M 100% /11204rdbms
10.0.0.39:/nfs_dir 67G 22G 43G 34% /nfs_client
[oracle@seconary ~]$ sudo umount /nfs_client
[oracle@seconary ~]$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
130G 80G 44G 65% /
/dev/sda1 99M 13M 82M 13% /boot
tmpfs 2.0G 746M 1.3G 38% /dev/shm
/dev/sdc1 17G 14G 1.9G 89% /11204grid
/dev/sdc2 18G 17G 56M 100% /11204rdbms
[oracle@seconary ~]$
----经测试在suse 11,仅首次运行sudo要输入ROOT密码,然后不用再输入密码了
oracle@suse11:~> more /etc/issue
Welcome to SUSE Linux Enterprise Server 11 (x86_64) - Kernel \r (\l).
suse11:~ # su - oracle
oracle@suse11:~> sudo mount /dev/sdb1 /oradata
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.
root's password:
oracle@suse11:~> df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 67G 22G 43G 34% /
udev 1.9G 108K 1.9G 1% /dev
/dev/sdb1 3.0G 69M 2.8G 3% /oradata
oracle@suse11:~> sudo umount /oradata
oracle@suse11:~> df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 67G 22G 43G 34% /
udev 1.9G 108K 1.9G 1% /dev
oracle@suse11:~>
oracle@suse11:~>
oracle@suse11:~>
oracle@suse11:~> df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 67G 22G 43G 34% /
udev 1.9G 108K 1.9G 1% /dev
oracle@suse11:~> sudo mount /dev/sdb1 /oradata
oracle@suse11:~>
---重启后,同上,首次要输入密码,然后不用再输入密码
suse11:~ # su - oracle
oracle@suse11:~> sudo mount /dev/sdb1 /oradata
root's password:
Sorry, try again.
root's password:
oracle@suse11:~> df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 67G 22G 43G 34% /
udev 1.9G 108K 1.9G 1% /dev
/dev/sdb1 3.0G 69M 2.8G 3% /oradata
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/9240380/viewspace-1972742/,如需转载,请注明出处,否则将追究法律责任。