LoginSignup
3
3

More than 5 years have passed since last update.

bashログイン、MySQLログインのユーザを確認、追加設定する

Last updated at Posted at 2015-09-17

bashログイン

ユーザの確認

$ cat /etc/passwdでも確認出来ますが、以下のコマンドを使うとユーザ名だけを抜き出せます。

$ cat /etc/passwd|sed -e 's/:.*//g'

ユーザの作成

root権限になる

$ su

ユーザ追加

hogeユーザの作成
# useradd hoge

パスワードの設定

hogeユーザにパスワード設定
# passwd hoge

console
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"

/etc/ssh/sshd_config
PermitRootLogin no
# the setting of "PermitRootLogin without-password".

と出ればもう弄らなくてOK

/etc/ssh/sshd_config
#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

/etc/ssh/sshd_config
  41 #LoginGraceTime 2m
  42 #PermitRootLogin yes
  43 #StrictModes yes
  44 #MaxAuthTries 6
  45 #MaxSessions 10

42行目付近にある #PermitRootLogin yes のコメントアウトを外して、yesnoにする

/etc/ssh/sshd_config
  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でパス入力を省略可
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3