ssh鍵をリモートサーバーに設置し、ローカルから作成した一般ユーザーでログインしたい。
sudo権限を付与adduser vpsuser
passwd vpsuservisudoコマンドでsudoersというファイルを編集・内容の確認を行う。
su -
visudo## Allows people in group wheel to run all commands
%wheel ALL=(ALL) ALL
## Same thing without a password
# %wheel ALL=(ALL) NOPASSWD: ALL%wheel ALL=(ALL) ALLの行がコメントアウトされていれば外す。
(wheelグループにすべてのコマンドの実行権限を与えるようになる。)
※ # %wheel ALL=(ALL) NOPASSWD: ALLをコメントアウトすると、
sudoの実行をパスワードなしで許可する設定となる。
usermod -aG wheel vpsuserid vpsusergroups
sudo su -ローカルでssh用の秘密鍵と公開鍵を作成する。
ssh-keygen -t rsa -C "[email protected]"
chmod 600 test_vps_id_rsascp ~/.ssh/test_vps_rsa.pub [email protected]:~/
ssh [email protected]mkdir .ssh
chmod 700 .ssh/
mv test_vps_id_rsa.pub .ssh/authorized_keys
chmod 600 .ssh/authorized_keyssudo su
vim /etc/ssh/sshd_configPermitRootLogin noでrootでアクセスできないように。
PasswordAuthentication noでパスワードでログイン出来ないように設定する。
PermitRootLogin no
PasswordAuthentication no設定を反映する。
systemctl restart sshd Host example.com
HostName example.com
User vpsuser
Port 22
IdentityFile ~/.ssh/test_vps_id_rsa
TCPKeepAlive yesssh example.com\(^o^)/