#author("2024-02-20T04:20:03+00:00","","")
#author("2024-02-20T04:20:10+00:00","","")
#topicpath
----
//ここにコンテンツを記述します。
#contents

**sudoって [#iee6bb14]

sudoは一般ユーザに特定のrootコマンドを実行できるようにするコマンドです。

例:
 [hogehoge@www ~]$ tail /var/log/messages
 tail: `/var/log/messages' を 読み込み用でオープンできません: 許可がありません
 [hogehoge@www ~]$ 
通常はこうですよね。これを下記のように実行すると、、

 [hogehoge@www ~]$ sudo tail /var/log/messages
 ... ナントカカントカ
 [hogehoge@www ~]$ 
ってrootで実行したかのようになります。((初回はそのアカウントのパスワードを求めてきます))


**やってみる [#af422833]
通常何も設定していないと、
 [hogehoge@www ~]$ sudo tail /var/log/messages
 hogehoge is not in the sudoers file.  This incident will be reported.
 [hogehoge@www ~]$ 
っていうように「このアカウントはこのコマンド使えないよ」って言われてしまうので、設定を追加します。

 [root@www ~]# visudo 
って実行すると、viでsudoの設定ファイルを開くことが出来るので、たとえば

 ## Allows members of the users group to shutdown this system
 # %users  localhost=/sbin/shutdown -h now
 %hogehoge ALL=(ALL) ALL
などと最後に追加すると、 hogehoge ユーザにすべてのコマンドのroot権限を付与するってなります。
 %hogehoge ALL=(ALL) ALL
は
 %ユーザ名 接続元=(どのユーザで(省略するとroot)) 実行可能なコマンド
ってことみたいです。その他指定方法はこんな感じ。。
 %hogehoge ALL=/usr/bin/tail  tailを実行可能
 %hogehoge ALL=/usr/bin/  bin以下のコマンドを実行可能
等が設定できます。実行すると、確かにナントカカントカが表示されました。。


-[[sudoによる管理者権限の付与>http://bit.ly/12UVkPU]]
-[[sudoの設定>http://bit.ly/ZVVrTv]]




**sudo を実行するとエラーになるばあい [#i43055c5]
 sudo: sorry, you must have a tty to run sudo
って出る場合、端末じゃないとダメって縛りがあるみたいので下記の通り設定を変更します。
 [root@www ~]# visudo
 ....
 #
 # Disable "ssh hostname sudo <cmd>", because it will show the password in clear. 
 #         You have to run "ssh -t hostname sudo <cmd>".
 #
 #Defaults    requiretty    <- コメントアウト

これで問題なしです

[[sudo: sorry, you must have a tty to run sudo Fedora>http://old.ikoinoba.net/index.php?UID=1188143501]]



**sudo: no tty present and no askpass program specified [#p2d1ddfa]
このエラーが出る場合、ttyを割り当てるか、askpassプログラムを指定せいっていわれてます。
[[ssh で sudo 実行>http://fishrimper.blogspot.jp/2012/09/ssh-sudo.html]]
っていくつか回避方法があるぽいですね。少なくともsshとかでやる場合は
 Defaults   visiblepw
って指定にしておけば、対話式にパスワードを入力できるぽいです。

cronとかJenkinsで使う分には対話的にできないわけで、その場合
 %hogehoge ALL=NOPASSWD: /bin/rm,/bin/cp
などとして、コマンド単位でパスワードナシを許可するようにするみたいです。



----
この記事は
#vote(おもしろかった[38],そうでもない[7])
#vote(おもしろかった[39],そうでもない[7])

#comment
#topicpath


SIZE(10){現在のアクセス:&counter;}

トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS