ssh证书登录方式

在/etc/ssh/sshd_confi.

在/etc/ssh/sshd_config中将以下注释去掉(去掉行首的#号)

 

  1. RSAAuthentication yes
  2. PubkeyAuthentication yes
  3. AuthorizedKeysFile  %h/.ssh/authorized_keys

  4. PasswordAuthentication no

 

加入登录通知机制:

/etc/pam.d/sshd

加入 session optional pam_exec.so seteuid /root/notify.sh

linux下ssh登录限制ip的方法

vi /etc/hosts.allow
sshd:192.168.0.100:allow          //允许IP 192.168.0.100 登录
sshd:192.168.0.:allow            //允许IP 192.168.0.  网段登录
sshd:all:deny                     //禁止其他的所有IP登录
或者
sshd:223.227.223.*:allow              //允许IP 223.227.223.*   网段登录
sshd:192.168.0.*:allow                //允许IP 192.168.0.*  网段登录
sshd:all:deny                                //禁止其他的所有IP登录

fedora下 修改后保存后生效

 

客户端

ssh可以使用密钥对互相建立信任,以后再链接信任的计算机就不需要输入密码了。

1、建立密钥对
niu@niu:~$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/niu/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/niu/.ssh/id_rsa.
Your public key has been saved in /home/niu/.ssh/id_rsa.pub.
The key fingerprint is:
27:00:f4:ce:a0:6f:61:a8:55:27:af:9a:bc:2b:d5:21 niu@niu
niu@niu:~$
过程中就一直按回车即可。此时会在 /home/niu/.ssh/ 目录下生成一对文件 id_rsa, id_rsa.pub

2、配置远程计算机
将id_ras.pub文件复制到远程计算机待登录用户个人目录下的.ssh目录中(如不存在自己创建),并将文件名改为 authorized_keys

3、完成