一、设置ssh登录IP限制

第一步:修改配置文件/etc/hosts.allow

sshd:192.168.213.32:allow  # IP改成自己的pc的IP

第二步:修改配置文件/etc/hosts.deny

sshd:all:deny  # 拒绝全部IP

第三步:重启ssh服务生效

service sshd restart

二、设置ssh秘钥方式登录

第一步:制作密钥对

[root@localhost ~]# ssh-keygen #输入命令Generating public/private rsa key pair.Enter file in which to save the key (/root/.ssh/id_rsa):  #直接回车 enterEnter passphrase (empty for no passphrase):  #输入复杂度高的密码Enter same passphrase again:   #再输入复杂度高的密码Your identification has been saved in /root/.ssh/id_rsa. #私钥保存的位置Your public key has been saved in /root/.ssh/id_rsa.pub. #公钥保存的位置

第二步:在服务器上安装公钥

cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys  && chmod 600 /root/.ssh/authorized_keys
 && chmod 700 root/.ssh

第三步:设置ssh,打开秘钥登录功能

编辑 /etc/ssh/sshd_config 文件,进行如下设置:

RSAAuthentication yes #开启秘钥登录PubkeyAuthentication yes #开启秘钥登录PermitRootLogin yes #开启root登录PasswordAuthentication no #关闭密码登录

第四步:下载秘钥文件到本地电脑

/root/.ssh/id_rsa #把改文件下载到本地。

第五步:重启服务端sshd服务生效

service sshd restart