免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1347 | 回复: 0
打印 上一主题 下一主题

Installing and configuring sudo on Solaris 7 & 8 [复制链接]

论坛徽章:
2
双鱼座
日期:2014-02-23 12:10:03操作系统版块每日发帖之星
日期:2015-12-17 06:20:00
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-07-10 00:49 |只看该作者 |倒序浏览
Introduction
sudo (Super User Do) is a very useful program that allows a system administrator to give certain users the ability to run some (or all) commands as root. It's described here specifically as a means of running the ISP connection scripts described in Configuring PPP on Solaris to connect to an ISP but has many other applications. These connection scripts must be run as root but it's not advisable to connect to the Internet while logged in as root, especially if you run a Web browser. sudo enables these scripts to be run with superuser privileges while logged in as an ordinary user.
sudo is supplied in source form and you need to compile it. This isn't difficult! Before doing so, you need to have installed the g(un)zip program and a C compiler. Both of these are freely downloadable from the Net and instructions for installing C and gzip are here.
--------------------------------------------------------------------------------
Installing sudo
1. Download the source code:
The source of sudo is available from
http://www.courtesan.com/sudo/.
At the time of writing, the latest version is V1.6.3 and the source code is provided as a compressed tar archive in the file sudo-1.6.3.tar.gz . Download this file to a temporary directory, such as /tmp.
2. Prepare the source code for compilation:
Log in as root, make a directory at a convenient point in the file system to hold the source code and copy the source into this directory. For example:
# mkdir -p /opt/source/sudo
# cd /opt/source/sudo
# cp /tmp/sudo-1.6.3.tar.gz .
Unzip and untar the source and then change to the directory created by tar:
# gunzip sudo*
# tar xvf sudo*
# cd sudo-1.6.3
At this point, you may like to have a look at the README, INSTALL and FAQ files.
3. Compile the source code and install sudo:
Configure the compilation process for your system:
# ./configure
Compile the source code:
# make
And install the compiled code:
# make install
This install the sudo program into /usr/local/bin, the visudo script (see later) into /usr/local/sbin and the manual page into subdirectories of /usr/local/man.
4. Modify the search path:
If you haven't already done so for other software, you now need to modify the search paths so that the system can find the sudo program and its manual pages. If you're running the CDE windowing system, this is done by editing the file /.dtprofile and adding the following lines (if they aren't already there) to the end of this file:
PATH=$PATH:/usr/local/bin:/usr/local/sbin:/usr/ccs/bin
MANPATH=$MANPATH:/usr/man/:/usr/local/man
It's advisable to log out and log in again at this point to activate these changes. Make sure that the system can find the sudo program:
# sudo -V
(that's an upper case "V") and that you can display the manual pages:
# man sudo
# man visudo
# man sudoers
5. Configure sudo:
sudo is controlled by its configuration file /etc/sudoers. The program has a rich selection of configuration options and you may like to read the man page for sudoers and examine the sample configuration file which you'll find in sample.sudoers in the source code directory.
The instructions below describe how to create an sudoers file which allows any user to run the /dialup and /hangup scripts defined in Configuring PPP on Solaris to connect to an ISP and allows a particular user to run any command as root.
One potential difficulty is that the /etc/sudoers file must be edited using the visudo program and not directly in your editor of choice. visudo uses the "vi" editor and this means that you need at least a basic understanding of how to use this editor. If you aren't already familiar with vi, you'll have to learn it sooner or later so now's a good time to start! But don't worry if you've never used it before - I'll include enough instruction here to enable you to edit the short file created by the installation process and append a couple of lines to it.
To edit /etc/sudoers, make sure you're logged in as root and type:
# /usr/local/sbin/visudo
This starts the vi editor and displays the initial /etc/sudoers file. vi uses what appear at first sight to be commands that aren't exactly intuitive. If you're not familiar with vi, type the following exactly as it appears and note that commands in vi are case sensitive. So don't type a lower-case "g" when the instructions show an upper-case "G".
Move the cursor to the end of the file by typing an upper-case G:
G
and open a new line just beyond the last line in the file by typing a lower-case o:
o
vi is now in "edit" mode and anything you type is inserted into the file. If you want everyone (all users) to be able to run the /hangup and /dialup scripts, type the following:
ALL ALL=/dialup,/hangup
with a TAB character after the first "ALL". That line tells sudo that all users are allowed to execute the scripts /hangup and /dialup as if they were root.
If you want to give just one user, say jim, the ability to run the scripts, type the following instead:
jim ALL=/dialup,/hangup
You may like to add another line telling sudo that your own personal user is allowed to do anything as root. Press the ENTER key and, if your own personal user is mike, you'd type:
mike ALL=(root) ALL
again with a TAB character after "mike".
Finally, switch vi back into command mode by pressing the ESCAPE key and exit vi by typing:
:wq
followed by ENTER. If you make a mistake at any time, just press the ESCAPE key followed by:
:q!
followed by ENTER and vi will return you to the shell command prompt without making any changes to the file.
6. Using sudo:
sudo is simple to use. To execute a command with root privilege, type:
$ sudo name-of-command
If this is the first time you've used sudo since logging in, sudo will ask for your password. The password required at this point is the user's own password, not the root password. So, if you've logged in as user jane and she wants to start a dialup connection to her ISP, she would type:
# sudo /dialup
and sudo responds:
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these two things:
       #1) Respect the privacy of others.
       #2) Think before you type.
Password:
Jane would then type her password and sudo will run the /dialup script for her with root privilege. If further commands are executed using sudo within 5 minutes, it will not ask for a password again.
But if Jane were to try and execute a command without having the necessary permission (as defined in the /etc/sudoers file), sudo will refuse to run it:
$ sudo vi /etc/passwd
Sorry, user jane is not allowed to execute "/usr/bin/vi /etc/passwd" as root on sunbeam.
In this example, sunbeam is the name of the machine.
If you'd prefer not to have to type a password at all, replace the two lines in /etc/sudoers with:
ALL NOPASSWD: ALL=/dialup,/hangup
mike ALL=(root) NOPASSWD: ALL
Do have a good look through the man page for sudo. The program has powerful features and you may like to use it for other purposes.


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/524/showart_34956.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP