一:简洁的配置文件

[root@cisco ~]# vi /etc/ssh/sshd_config

Port 22
Protocol 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
KeyRegenerationInterval 3600
ServerKeyBits 768
SyslogFacility AUTH
LogLevel INFO
LoginGraceTime 600
PermitRootLogin yes
PubkeyAuthentication yes
AuthorizedKeysFile

    .ssh/authorized_keys

RhostsAuthentication no
IgnoreRhosts yes
HostbasedAuthentication no
PasswordAuthentication no
PermitEmptyPasswords no
ChallengeResponseAuthent ication no
MaxStartups 20
Subsystem sftp /usr/libexec/openssh/sftp-server
~

二、应用公钥认证
1、原理:首先由用户生成一对密钥,而后将公钥保留在SSH服务器用户的目录下.ssh子目录中的authorized_key文件里(/root/.ssh/authorized_key).私钥保留在本地计算机.当用户登陆时,服务器查看authorized_key文件的公钥是否与用户的私钥对应,如果相符则容许登入,否则回绝.因为私钥只有保留在用户的本地计算机中,因而入侵者就算失去用户口令,也不能登陆到服务器.
2、启用公钥认证
批改配置文件/etc/ssh/sshd_config
将"PasswordAuthentication yes"批改为"PasswordAuthentication no"
3、生成密钥
[root@rain ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter 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.
The key fingerprint is:
4d:dd:48:af:76:c2:ba:a8:bc:20:f3:28:1d:6a:28:53root@rain.fish.com
4、将/root/.ssh/id_rsa.pub改名为/root/.ssh/authorized_keys
mv /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys
5、将私钥id_rsa拷贝到客户机
A:linux下能够拷贝到/root/.ssh/就能够间接应用了。

三、SSH服务的配置
1、配置SSH服务的运行参数,是通过批改配置文件/etc/ssh/sshd_config实现的。
2、因为SSH服务应用默认的配置曾经可能很好的工作,如果仅仅提供SSH服务不须要批改。这里只介绍一
些罕用的选项。

Port 22

定义了SSH服务监听的断口号,SSH服务默认应用的端口号是22

Proctocol 2,1

定义了SSH服务器应用SSH协定的程序。默意识先应用SSH2协定,如果不胜利则应用SSH1协定,为了平安起
见,能够设置只应用SSH2协定。

ListenAddress 0.0.0.0

定义SSH服务器帮定的IP地址,默认绑定服务器所有可用的IP地址.

PermitRootLogin yes

定义是否容许管理员登陆

PermitEmptyPasswords no

定义是否容许空明码登
参考链接:
2 Ways to login Linux server with SSH key