bashログイン
ユーザの確認
$ cat /etc/passwd
でも確認出来ますが、以下のコマンドを使うとユーザ名だけを抜き出せます。
$ cat /etc/passwd|sed -e 's/:.*//g'
ユーザの作成
root権限になる
$ su
ユーザ追加
hogeユーザの作成
# useradd hoge
パスワードの設定
hogeユーザにパスワード設定
# passwd hoge
Changing password for user hoge.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
MySQLユーザ
MySQLログイン
$ mysql -u root -p mysql
ユーザの確認
mysql> SELECT user, host FROM user;
ユーザの作成
ユーザ追加
hogeユーザの作成
mysql> CREATE USER 'hoge'@'localhost' IDENTIFIED BY 'パスワード';
権限付与
hogeユーザに権限を付与
mysql> GRANT ALL PRIVILEGES ON *.* TO 'hoge'@'localhost';
権限の確認
mysql> SHOW GRANTS for 'hoge'@'localhost';
おまけ
rootでのSSHログインを禁止する
root権限になる
$ su
現在の設定を確認
# cat /etc/ssh/sshd_config | grep "PermitRootLogin"
PermitRootLogin no
# the setting of "PermitRootLogin without-password".
と出ればもう弄らなくてOK
# PermitRootLogin yes
# the setting of "PermitRootLogin without-password".
と出たら↓へ
SSHの設定ファイルをバックアップ
# cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bu
rootログインの項目を編集
# vi /etc/ssh/sshd_config
41 #LoginGraceTime 2m
42 #PermitRootLogin yes
43 #StrictModes yes
44 #MaxAuthTries 6
45 #MaxSessions 10
42行目付近にある #PermitRootLogin yes
のコメントアウトを外して、yes
をno
にする
↓
41 #LoginGraceTime 2m
- 42 #PermitRootLogin yes
+ 42 PermitRootLogin no
43 #StrictModes yes
44 #MaxAuthTries 6
45 #MaxSessions 10
構文の確認
# sshd -t
設定を反映
# /etc/init.d/sshd restart
ユーザにsudoの実行権限を与える
root権限になる
$ su
sudo実行権限ファイルを変更
# visudo
- 普通のsudo
104 ## Allows people in group wheel to run all commands
105 %wheel ALL=(ALL) ALL
+ 106 %admin ALL=(ALL) ALL # ← これを追加
- NOPASSWD(sudo実行時にパスワードを再入力しない)版
104 ## Allows people in group wheel to run all commands
105 %wheel ALL=(ALL) ALL
+ 106 %admin ALL=(ALL) NOPASSWD: ALL # ← NOPASSWDでパス入力を省略可