#使用SSH安全登陸服務器
在服務器新建用戶
-
Unbentu中
adduser biyongyao
usermod -a -G sudo biyongyao
-
Centos中
adduser biyongyao
passwd biyongyao
usermod -a -G wheel biyongyao
在本機
ssh-keygen -t rsa -C “your [email protected]”
ssh-keygen
生成SSHscp ~/.ssh/id_rsa.pub [email protected]:
將SSH生成的公鑰發送到服務器用戶名爲biyongyao用戶的根目錄ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected]
將本機的id_rsa.pub加入到遠程的的可訪問列表裏面
在服務器中
mkdir ~/.ssh
touch ~/.ssh/authorized_keys
cat ~/id_rsa.pub >> ~/.ssh/authorized_keys
設置權限
chown -R biyongyao:biyongyao ~/.ssh
chmod 700 ~/.ssh
hmod 600 ~/.ssh/authorized_keys
禁用密碼,禁止根用戶登陸
- 找到 /etc/ssh/sshd_config
- 找到 PasswordAuthentication 註釋掉
- 找到 PermitRootLogin 註釋掉
- 重啓 Ubuntu sudo service ssh restart
- Centos sudo systemctl restart sshd.service