您的位置:首页 > 运维架构 > Linux

用密钥登录linux服务器

2017-09-27 15:37 253 查看
1.生成公钥私钥

$ ssh-keygen -t rsa

Generating public/private rsa key pair.

Enter file in which to save the key (/home/leon/.ssh/id_rsa): testa

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in testa.

Your public key has been saved in testa.pub.

The key fingerprint is:

85:97:91:94:4a:21:00:d5:08:e3:cc:b0:63:0b:0f:cf leon@xxxx

将testa拷入/home/leon/.ssh/id_rsa

将testa.pub拷入/home/leon/.ssh/authorized_keys

这两个文件同时可以拷给其他linux机器相应的.ssh目录下。

这时用scp等拷贝文件时也不必输密码了。

2.

用超级用户权限修改/etc/ssh/sshd_config

RSAAuthentication yes

PubkeyAuthentication yes

AuthorizedKeysFile      .ssh/authorized_keys

如果同时修改:

ChallengeResponseAuthentication no

Pa
4000
sswordAuthentication no

UsePAM no

则会禁止采用password登录

重启sshd

service sshd restart

如果不修改.ssh为0700,将打印

Server refused our key

这是为了防止私钥被人拷走设的权限保护。

3.将testa的私钥传到windows下

用putty的puttygen导入该文件,再保存私钥为zhh.ppk,公钥为zhh.pub

因为putty的rsa的私钥和openssh的不兼容,所以要导一下。

4.putty配置ssh的auth的key文件为刚生成的zhh.ppk。

ssh的data也可以将用户名配为登录用户zhouhh,否则putty登录时会提示用户名。

5.连接服务器,不用输入密码直接登录了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: