Linux最強Tips集ユーザー管理 > 一般ユーザーでroot権限のコマンドを実行するには

全200ページ期間限定無料モニターレポートをあなたにプレゼント中

当サイトにアクセスありがとうございます。
ただ今、アクセスしてくれたお礼に期間限定で合計200ページ以上の無料モニターレポート(2冊)をプレゼント しています。いますぐお申込みフォームより限定モニターレポートをダウンロードしてください。

●完全無料でLinuxをWindows上で動作させるマニュアル(全80ページ)

●Linux挫折者・初心者向けサーバー構築マニュアル
【イントラサーバー構築Vine Linux4.2編】(全120ページ)

姓: 名:(ニックネーム可)
メールアドレス:

現在、モニターとして上記の2冊のレポートを無料で差し上げています。
いますぐ上記お申込みフォームから、モニターレポートを手に入れてください。

このレポートさえあれば、どんな人でもいますぐLinuxをはじめられます。

一般ユーザーでroot権限のコマンドを実行するには




スポンサードリンク

あるコマンドを実行するときにのみ、root権限のコマンドを使用したいという場合があります。そのようなときには、sudoコマンドを使うと便利です。

sudoコマンドの引数に実行したいコマンドを指定して実行することで、rootコマンドを実行することができます。しかし、sudoコマンドを実行する際には、あらかじめ/etc/sudoersファイルに実行を許可したいユーザを設定しておく必要があります。

この/etc/sudoersファイルに記述するユーザーは信頼のあるユーザーを設定する必要があります。

また、sudoコマンドを実行したログはsyslogデーモンを経由して、ログファイルに記述されるので、セキュリティ管理上のメリットがあります。誰がいつどんなコマンドをsudoコマンドを使用したのかを詳しく知ることができます。

sudo -u <ユーザー名> <実行するコマンド>

一般ユーザーでroot権限のコマンドを実行するには

[pakira@tiger pakira]$ su -
Password:
[root@tiger root]# visudo ←/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

# Runas alias specification

# User privilege specification
root ALL=(ALL) ALL
pakira 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

# Samples
# %users ALL=/sbin/mount /cdrom,/sbin/umount /cdrom
# %users localhost=/sbin/shutdown -h now
------------------------------------------------------------
:wqで保存終了します。


sudoコマンドを実行してみる

[pakira@tiger pakira]$ sudo su - ←一般ユーザーでsuコマンドを実行します。

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.

Password: ←一般ユーザーのパスワードを入力します。
[root@tiger root]#   ←root権限になります。

ログを確認する

[root@tiger root]# tail /var/log/messages
Oct 4 10:53:45 tiger iptables: Flushing all current rules and user defined chains: succeeded
Oct 4 10:53:45 tiger iptables: Clearing all current rules and user defined chains: succeeded
Oct 4 10:53:45 tiger iptables: Flushing all current rules and user defined chains: succeeded
Oct 4 10:53:45 tiger iptables: Clearing all current rules and user defined chains: succeeded
Oct 4 10:53:45 tiger iptables: Applying iptables firewall rules succeeded
Oct 4 10:55:23 tiger sudo: pakira : user NOT in sudoers ; TTY=pts/0 ; PWD=/home/pakira ; USER=pakira ; COMMAND=adduser
Oct 4 11:01:36 tiger su(pam_unix)[1335]: session opened for user root by pakira(uid=500)
Oct 4 11:06:40 tiger su(pam_unix)[1335]: session closed for user root
Oct 4 11:06:48 tiger sudo: pakira : TTY=pts/0 ; PWD=/home/pakira ; USER=root ; COMMAND=/bin/su -
Oct 4 11:06:48 tiger su(pam_unix)[1369]: session opened for user root by pakira(uid=0)




スポンサードリンク

Linux最強Tips集:当サイトについて

  • Linux最強Tips集は個人で運営しているサイトです。
  • ご意見、ご質問はメールでお願いいたします。

30日間 Linux無料メールセミナー

  • 初心者のあなたも30日でLinuxがマスターできる!
  • 姓: 名:
    メールアドレス: 
  • 登録するだけで、無料Linuxメールセミナーを受講できます。登録してくれたあなただけに、Linuxコマンドからサーバー構築までの基礎を教えます。
  • ※登録すると、自動的にmag2で発行しているメールマガジンに登録されます。予め御了承ください。

Linux起動Tips

ユーザー管理Tips

ディレクトリ・ファイル操作Tips

ディスク操作Tips

テキスト処理Tips

システム管理Tips

RPM Tips

ネットワークTips

セキュリティTips

サーバー管理Tips

Linux用語

相互リンク

おススメリンク

copyright(c) 2004-6 Linux最強Tips集 All Rights Reserved.