2020-02-14
SSH**登录让Linux VPS/服务器更安全
Linux SSH登录有两种:
1、使用密码验证登录通常VPS或服务器开通后都是直接提供IP和root密码,使用这种方式就是通过密码方式登录。如果密码不够强壮,而且没有安装DenyHosts之类的防止SSH密码**的软件,那么系统安全将存在很大的隐患。
2、使用**验证登录基于**的安全验证必须为用户自己创建一对**,并把共有的**放在需要访问的服务器上。当需要连接到SSH服务器上时,客户端软件就会向服务器发出请求,请求使用客户端的**进行安全验证。服务器收到请求之后,先在该用户的根目录下寻找共有**,然后把它和发送过来的公有**进行比较。如果两个**一致,服务器就用公有的**加密“质询”,并把它发送给客户端软件(putty,xshell等)。客户端收到质询之后,就可以用本地的私人**解密再把它发送给服务器,这种方式是相当安全的。
一、生成**
因为puttygen生成的**有问题可能会出现:“Server refused our key”,最好使用XShell生成**或者在远程Linux VPS/服务器生成**。
1、在Linux远程服务器生成**:登录远程Linux VPS/服务器,执行:[email protected]:~# ssh-****** -t rsa //先运行这个命令Generating public/private rsa key pair.Enter file in which to save the key (/root/.ssh/id_rsa): //直接回车Created directory ‘/root/.ssh’.Enter passphrase (empty for no passphrase): //输入**密码Enter same passphrase again: //重复**密码Your identification has been saved in /root/.ssh/id_rsa. //提示公钥和私钥已经存放在/root/.ssh/目录下Your public key has been saved in /root/.ssh/id_rsa.pub.The key fingerprint is:15:23:a1:41:90:10:05:29:4c:d6:c0:11:61:13:23:dd [email protected] key’s randomart image is:±-[ RSA 2048]----+|=&@Bo+o o.o ||=o=.E o . o || . . . || . || S || || || || |±[email protected]:~#将/root/.ssh/下面的id_rsa和id_rsd.pub妥善保存。
二、将**添加到远程Linux服务器
1、用winscp,将/root/.ssh/下面(如果没有则创建此目录)下载到本地备用,在服务器上.ssh/目录下,cat id_rsa.pub >> authorized_keys,再执行:chmod 600 /root/.ssh/authorized_keys 修改权限。
2、修改/etc/ssh/sshd_config 文件,将RSAAuthentication 和 PubkeyAuthentication 后面的值都改成yes ,保存。如果这两项前面有 # 符号说明是注释掉的,需要去掉 # 符号。
3、重启sshd服务,Debian/Ubuntu执行/etc/init.d/ssh restart ;CentOS执行:/etc/init.d/sshd restart 如果不存在可以执行:service sshd restart。 不行的话使用 /bin/systemctl restart sshd.service
四、修改远程Linux服务器sshd服务配置
1、修改/etc/ssh/sshd_config 文件将PasswordAuthentication yes 修改成 PasswordAuthentication no2、重启sshd服务Debian/Ubuntu执行/etc/init.d/ssh restart ;CentOS执行:/bin/systemctl restart sshd.serviceok,设置完成。