こんにちは! JQです。
前回は『 SDK編~botoでS3アップロード~ 』 ということで、botoを利用してS3にアップロードしてみました。
今回は『EC2編~sudo権限~』と題して、ec2-userのsudo権限を制限してみたいと思います。
パスワード設定
1.パスワード設定
先ずはec2-userにパスワードを設定します。
1$ sudo passwd ec2-user2Changing password for user ec2-user.3New password:4Retype new password:5passwd: all authentication tokens updated successfully.2.sudo権限の変更
/etc/sudoers.d/cloud-init でsudoコマンド時にパスワードを入力するように変更します。
1$ sudo visudo -f /etc/sudoers.d/cloud-init2#ec2-user ALL = NOPASSWD: ALL3ec2-user ALL = (ALL) ALL3.確認
実際にsudoを試してみます。
1$ ls /root/2ls: cannot open directory /root/: Permission denied34$ tail /var/log/messages5We trust you have received the usual lecture from the local System6Administrator. It usually boils down to these three things:78 #1) Respect the privacy of others.9 #2) Think before you type.10 #3) With great power comes great responsibility.1112[sudo] password for ec2-user:1314Dec 18 10:39:01 ip-10-133-159-175 udevadm[1145]: --type=failed is deprecated and will be removed from a future udev release.15Dec 18 10:39:04 ip-10-133-159-175 ntpdate[1172]: step time server 219.123.70.90 offset -0.096534 sec16Dec 18 10:39:04 ip-10-133-159-175 ntpd[1178]: ntpd 4.2.6p5@1.2349-o Sat Mar 23 00:37:31 UTC 2013 (1)17Dec 18 10:39:04 ip-10-133-159-175 ntpd[1179]: proto: precision = 1.191 usec18Dec 18 10:39:04 ip-10-133-159-175 ntpd[1179]: 0.0.0.0 c01d 0d kern kernel time sync enabled19Dec 18 10:39:04 ip-10-133-159-175 ntpd[1179]: Listen and drop on 0 v4wildcard 0.0.0.0 UDP 12320Dec 18 10:39:04 ip-10-133-159-175 ntpd[1179]: Listen normally on 1 lo 127.0.0.1 UDP 12321Dec 18 10:39:04 ip-10-133-159-175 ntpd[1179]: Listen normally on 2 eth0 10.133.159.175 UDP 12322Dec 18 10:39:04 ip-10-133-159-175 ntpd[1179]: peers refreshed2324Dec 18 10:39:04 ip-10-133-159-175 ntpd[1179]: Listening on routing socket on fd #19 for interface updates25:4.sudoでの特定のコマンドを禁止する。
また、sudoで特定のコマンドを制限したい場合は下記の様にします。
1$ sudo visudo -f /etc/sudoers.d/cloud-init2Cmnd_Alias NOTSU = /bin/su34#ec2-user ALL = NOPASSWD: ALL5ec2-user ALL = (ALL) ALL,!NOTSU67$ sudo su -8[sudo] password for ec2-user:9Sorry, user ec2-user is not allowed to execute '/bin/su -' as root on ip-00-000-000-000.いかがでしたでしょうか?
次回は『 EC2編~lsyncdでリアルタイムにファイル同期①~ 』と題して、lsyncdで同期処理をしてみたいと思います。
お楽しみに!