ใน Ubuntu นั้น เพื่อความปลอดภัยของระบบ โดยปกติจะไม่มีการใช้งานผู้ใช้งานที่ชื่อ root เนื่องจากในขั้นตอนการติดตั้งไม่มีการกำหนดรหัสผ่านให้ root (แต่ถ้าหลังจากติดตั้งเสร็จแล้ว มีการกำหนดรหัสผ่านให้ root ก็จะสามารถล็อกอินเป็น root ได้)
ถ้าจะต้องใช้คำสั่งที่ต้องใช้สิทธิ์ของ root จะต้องใช้ผ่านคำสั่ง sudo โดยหลังจากติดตั้งเสร็จผู้ใช้งานที่ถูกสร้างขึ้นในตอนติดตั้งเพียงคนเดียวเท่านั้นที่มีสิทธิ์รันคำสั่งในฐานะ root ถ้าต้องการให้ผู้ใช้งานคนอื่นสามารถทำได้ด้วย จะต้องกำหนดให้ผู้ใช้งานคนนั้นเป็นสมาชิกของกลุ่ม admin
ตัวอย่างการใช้งาน
|
suchart@myubuntu:~$ iptables -L –n
WARNING: Error inserting x_tables (/lib/modules/2.6.20-15-generic/kernel/net/netfilter/x_tables.ko): Operation not permitted FATAL: Error inserting ip_tables (/lib/modules/2.6.20-15-generic/kernel/net/ipv4/netfilter/ip_tables.ko): Operation not permitted iptables v1.3.6: can’t initialize iptables table `filter’: Permission denied (you must be root) Perhaps iptables or your kernel needs to be upgraded.
# sudo ตามด้วยคำสั่ง และพารามิเตอร์ ที่ต้องการรัน
suchart@myubuntu:~$ sudo iptables -L –n
Password: # ป้อนรหัสผ่านของผู้ใช้งานในปัจจุบัน ในที่นี้คือ suchart ไม่ใช่ root
Chain INPUT (policy ACCEPT) target prot opt source destination
Chain FORWARD (policy ACCEPT) target prot opt source destination
Chain OUTPUT (policy ACCEPT) target prot opt source destination suchart@myubuntu:~$
|
โดยปกติ ถ้ามีการใช้งาน sudo ได้สำเร็จ ในครั้งต่อไปที่ใช้งานภายใน 15 นาที จะไม่ต้องใส่รหัสผ่าน
ถ้าต้องการใช้งาน root แบบ interactive ใช้คำสั่ง sudo -i
suchart@myubuntu:~$ sudo -i
root@myubuntu:~#
Update 20080426
แก้ไขค่าคอนฟิก ใช้คำสั่ง visudo
# visudo
# /etc/sudoers
#
# This file MUST be edited with the ‘visudo’ command as root.
#
# See the man page for details on how to write a sudoers file.
#
Defaults env_reset
# Uncomment to allow members of group sudo to not need a password
# %sudo ALL=NOPASSWD: ALL
# Host alias specification
# User alias specification
# Cmnd alias specification
# User privilege specification
root ALL=(ALL) ALL
# Members of the admin group may gain root privileges
#%admin ALL=(ALL) ALL
%admin ALL=NOPASSWD: ALL # admin group ไม่ต้องใส่รหัสผ่าน เวลาเรียกใช้ sudo
.
ตัวอย่างไฟล์คอนฟิก จาก Genroo
mygentoo ~ # cat /etc/sudoers
# sudoers file.
#
# This file MUST be edited with the ‘visudo’ command as root.
#
# See the sudoers man page for the details on how to write a sudoers file.
#
# Host alias specification
# User alias specification
# Cmnd alias specification
# Defaults specification
# Reset environment by default
Defaults env_reset
# Uncomment to allow users in group wheel to export variables
# Defaults:%wheel !env_reset
# Allow users in group users to export specific variables
# Defaults:%users env_keep=TZ
# Allow specific user to bypass env_delete for TERMCAP
# Defaults:user env_delete-=TERMCAP
# Set default EDITOR to vi, and do not allow visudo to use EDITOR/VISUAL.
# Defaults editor=/usr/bin/vim, !env_editor
# Runas alias specification
# *** REMEMBER ***************************************************
# * GIVING SUDO ACCESS TO USERS ALLOWS THEM TO RUN THE SPECIFIED *
# * COMMANDS WITH ELEVATED PRIVILEGES. *
# * *
# * NEVER PERMIT UNTRUSTED USERS TO ACCESS SUDO. *
# ****************************************************************
# User privilege specification
root ALL=(ALL) ALL
# Uncomment to allow people in group wheel to run all commands
# %wheel ALL=(ALL) ALL
# Same thing without a password
%wheel ALL=(ALL) NOPASSWD: ALL
# Users in group www are allowed to edit httpd.conf using sudoedit, or
# sudo -e, without a password.
# %www ALL=(ALL) NOPASSWD: sudoedit /etc/httpd.conf
# Samples
# %users ALL=/bin/mount /cdrom,/bin/umount /cdrom
# %users localhost=/sbin/shutdown -h now
mygentoo ~ #
ข้อมูลเพิ่มเติม
ไฟล์ /etc/sudoers
man sudo_root
man sudo
man sudoers
man visudo
รออ่านต่อครับ
ความเห็น โดย teelaband — กรกฎาคม 24, 2007 @ 1:31 am |