さくらVPSサーバー初期設定
参考URL
サーバーへのssh接続とユーザー設定
rootでssh接続
$ ssh root@{IPアドレス}
CentOSアップデート
# yum update
一般ユーザーの作成
# adduser {ユーザー名}
ユーザーのパスワードを設定
# passwd {ユーザー名}
作成した一般ユーザーでssh接続し、rootに切り替える
# ssh {ユーザー名}@{IPアドレス}
# su
セキュリティを高めるための権限設定
rootからのssh接続を禁止する
- /etc/ssh/sshd_configを下記の通り編集し、sshdを再起動
- 前:#PermitRootLogin yes
- 後:PermitRootLogin no
# cd /etc/ssh //移動 # cp sshd_config sshd_config.bak //BAKをとっておく # vi sshd_config //編集 # systemctl restart sshd.service //再起動
作成した一般ユーザーをwheelグループに追加する
# gpasswd -a {ユーザー名} wheel
Usage: gpasswd [option] GROUP
Options:
-a, –add USER add USER to GROUP
-d, –delete USER remove USER from GROUP
-h, –help display this help message and exit
-Q, –root CHROOT_DIR directory to chroot into
-r, –delete-password remove the GROUP’s password
-R, –restrict restrict access to GROUP to its members
-M, –members USER,… set the list of members of GROUP
-A, –administrators ADMIN,…
set the list of administrators for GROUP
Except for the -A and -M options, the options cannot be combined.
- 所属グループはidコマンドかgropusコマンドで確認できる
- 例:ユーザー名が hoge の場合
```sh
# id hoge
uid=1000(hoge) gid=1000(hoge) groups=1000(hoge),10(wheel)
# groups hoge
hoge : hoge wheel
root権限に切り替えられるユーザーをwheelグループに所属するユーザーのみに制限する
- /etc/pam.d/suを編集
- 下記2行目のコメントアウトを外す
# vi /etc/pam.d/su
# Uncomment the following line to require a user to be in the "wheel" group.
#auth required pam_wheel.so use_uid
wheelグループに所属するユーザーはパスワードなしでrootへ切替可能にする
- /etc/pam.d/suを編集
- 下記2行目のコメントアウトを外す
# vi /etc/pam.d/su
# Uncomment the following line to implicitly trust users in the "wheel" group.
#auth sufficient pam_wheel.so trust use_uid
wheelグループに所属するユーザーはsudoコマンドを実行可能にする
- visudoコマンドを使ってsudoersファイル(sudoコマンドのための設定ファイル)を下記の通り編集
- 下記2行目のコメントアウトを外す
# visudo
## Same thing without a password
# %wheel ALL=(ALL) NOPASSWD: ALL
ssh接続を鍵認証で行う
- あとでやる
しばらく使わないときはサーバーを停止しておく
# shutdown -h now
shutdown [OPTIONS...] [TIME] [WALL...]
Shut down the system.
--help Show this help
-H --halt Halt the machine
-P --poweroff Power-off the machine
-r --reboot Reboot the machine
-h Equivalent to --poweroff, overridden by --halt
-k Don't halt/power-off/reboot, just send warnings
--no-wall Don't send wall message before halt/power-off/reboot
-c Cancel a pending shutdown