您的位置:首页 > 其它

使用SSH安全登陆服务器

2017-08-07 22:16 218 查看

使用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 name@mail.com”


ssh-keygen
生成SSH

scp ~/.ssh/id_rsa.pub biyongyao@123.456.78.90:
将SSH生成的公钥发送到服务器用户名为biyongyao用户的根目录

ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.142.84
将本机的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

原文:http://biyongyao.com/archives/170
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: