一:简洁的配置文件[root@cisco~]#vi/etc/ssh/sshd_configPort22Protocol2HostKey/etc/ssh/ssh_host_rsa_keyHostKey/etc/ssh/ssh_host_dsa_keyKeyRegenerationInterval3600ServerKeyBits768SyslogFacilityAUTHLogLevelINFOLoginGraceTime600PermitRootLoginyesPubkeyAuthenticationyesAuthorizedKeysFile.ssh/authorized_keysRhostsAuthenticationnoIgnoreRhostsyesHostbasedAuthenticationnoPasswordAuthenticationnoPermitEmptyPasswordsnoChallengeResponseAuthenticationnoMaxStartups20Subsystemsftp/usr/libexec/openssh/sftp-server~2。使用公钥将密钥保存在SS1中。在服务器用户目录(/root/.ssh/authorized_key)的.ssh子目录中的authorized_key文件中。私钥存储在本地计算机上。当用户登录时,服务器会检查authorized_key文件中的公钥是否与用户的私钥对应,如果匹配则允许登录,否则拒绝。由于私钥只保存在用户本地电脑中,因此即使入侵者获得了用户密码,也无法登录服务器。2.启用公钥认证,修改配置文件/etc/ssh/sshd_config将"PasswordAuthenticationyes"改为"PasswordAuthenticationno"3.生成密钥[root@rain~]#ssh-keygen-trsaGeneratingpublic/privatersakeypair.输入要保存的文件key(/root/.ssh/id_rsa):Enterpassphrase(emptyfornopassphrase):Entersamepassphraseagain:Youridentificationhasbeensavedin/root/.ssh/id_rsa.Yourpublickeyhasbeensavedin/root/.ssh/id_rsa.pub。密钥指纹是:4d:dd:48:af:76:c2:ba:a8:bc:20:f3:28:1d:6a:28:53root@rain.fish.com4。/root/.ssh/id_rsa.pub改名为/root/.ssh/authorized_keysmv/root/.ssh/id_rsa.pub/root/.ssh/authorized_keys5.将私钥id_rsa复制到客户端A:复制即可到/root/.ssh/可以直接使用。三、SSH服务配置1、配置SSH服务的运行参数是通过修改配置文件/etc/ssh/sshd_config来实现的。2、由于SSH服务在默认配置下已经可以正常工作,如果只提供SSH服务,则无需修改。这里只介绍一些常用的选项。端口22定义了SSH服务监控的端口号。SSH服务使用的默认端口号是22。Proctocol2,1定义了SSH服务器使用SSH协议的顺序。默认情况下会优先使用SSH2协议,如果失败则使用SSH1协议。出于安全原因,您可以设置仅使用SSH2协议。ListenAddress0.0.0.0定义SSH服务器分配的IP地址,默认绑定服务器所有可用的IP地址。PermitRootLoginyes定义是否允许管理员登录。PermitEmptyPasswordsno定义是否允许空密码登录。参考链接:2WaystologinLinuxserverwithSSHkey
