工控机改装家庭智能中心--配置ssh证书登陆

1.在客户端的~/.ssh目录下生成私钥与公钥

ssh-keygen -t rsa

  rsa为一种加密算法,另外一种加密算法为dsa。会在当前目录下生成一个是公钥id_rsa.pub,一个是私钥id_rsa。

Generating public/private rsa key pair.
Enter file in which to save the key (/home/user/.ssh/id_rsa): xxx

  密钥文件名:xxx

Enter passphrase (empty for no passphrase):

  是否证书登录时需要密码,这里可以为空。

2.在服务器端配置SSH,注意是sshd_config

vim /etc/ssh/sshd_config

#允许用户自行使用成对的密钥系统登录服务器,公钥位置在~/.ssh/authorized_keys
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile      %h/.ssh/authorized_keys

#禁用root账户登陆 
PermitRootLogin no

#禁用密码登陆
PasswordAuthentication no

#仅允许特定用户
AllowUsers username

#SSH协议版本
Protocol 2

3.将客户端的公钥传给服务器端,并把公钥导入文件authorized_keys

客户端执行:
scp ~/.ssh/id_rsa.pub xxx@192.168.0.1:/home/xxx/.ssh
在服务器端~/.ssh目录下执行:
cat id_rsa.pub >> authorized_keys

4.在服务器端重启sshd服务

sudo /etc/init.d/sshd restart

5.在客户端将私钥加入ssh配置文件内中

sudo vim /etc/ssh/ssh_config

#指定私钥位置
IdentityFile ~/.ssh/nas_rsa

 

然后就可以每次使用证书登陆了。

posted on 2016-08-20 16:41  十点零九  阅读(311)  评论(0编辑  收藏  举报

导航