m_shige1979のときどきITブログ

プログラムの勉強をしながら学習したことや経験したことをぼそぼそと書いていきます

Github(変なおっさんの顔でるので気をつけてね)

https://github.com/mshige1979

sudo時にパスワードを使わない?

vagrantでは

sudoコマンド実行する際、パスワードを必要としないので疑問に思って適当にしらべた

sudo の設定は visudo を使わずに sudoers.d に書く

sudo - 何度も要求されるパスワード入力を省略する - Qiita

なんか”/etc/sudoers”あたりをいじれば特定のユーザーではパスワードを無効にできるようです

環境

初期実行コマンド
# iptables off
sudo chkconfig iptables off
sudo service iptables stop


# epel,remi
sudo rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
sudo rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

# developer
sudo yum -y update
sudo yum -y groupinstall "Development Tools"

httpdをインストール

sudo yum install -y httpd

ユーザー準備

hogeユーザーを作成
useradd --shell /bin/bash --home /home/hoge hoge
passwd hoge

serviceなどを実行しようとすると

[hoge@localhost ~]$ sudo service httpd start

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.

[sudo] password for hoge:

まあ、聞かれます

/etc/sudoers.dへ追加

vi /etc/sudoers.d/hoge
----
hoge    ALL=(ALL) NOPASSWD: ALL
----
パーミッション変更
chmod 440 /etc/sudoers.d/hoge

確認

実行
[hoge@localhost ~]$ sudo service httpd start
httpd を起動中: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName
                                                           [  OK  ]
[hoge@localhost ~]$

※作成したユーザーでserviceを起動できた

serviceやyumのみを有効にする場合
vi /etc/sudoers.d/hoge
----
hoge    ALL=(ALL) NOPASSWD: /sbin/service,/usr/bin/yum
----

※フルパスをカンマ区切りで設定したらできた


ただ、これをやるとパスワードなしでなんでもできそうな気がするので設定するユーザーなどには気をつける必要がありそう