欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

配置ssh免密登录

程序员文章站 2024-02-23 18:05:58
...

win上的ssh也是在~/.ssh目录。

生成ssh**

参考
Note:过程中使用phase是有必要的。否则的话会生成相同的id_rsa.pub

ssh-****** -t rsa

ssh config

code ~/.ssh/config

如下图配置。配置了好了之后可以直接ssh ubuntu进行登录。

Host ubuntu
    User kyle
    HostName 192.168.1.105
    Port 2222

设置ssh免密登录

ssh-copy-id [email protected]

说明:
ssh-copy-id 使用的前提是client, 已经有了.ssh以及在其内的非对称加密的公钥和私钥。如果没有的话,参考具体原理介绍中的做法。

可能会出现ssh-copy-id成功【成功是指将客户端的公钥~/.ssh/id_rsa.pub中的公钥拷贝到服务器~/.ssh/authorized_keys中】。但是无法免密登录的情况。检查/home/kyle文件的权限是不是755, 即drwxr-xr-x。如果不是 sudo chmod 0755 /home/kyle。 是的,不用使用-R参数。 所以直接将id_rsa.pub中的内容拷贝到authorized_keys也是可以实现免密登录的。

登出ssh

exit

具体原理介绍

SETTING UP PUBLIC KEY AUTHENTICATION FOR SSH
The following simple steps are required to set up public key authentication (for SSH):

Key pair is created (typically by the user). This is typically done with ssh-******.
Private key stays with the user (and only there), while the public key is sent to the server. Typically with the ssh-copy-id utility.
Server stores the public key (and marks it as authorized).
Server will now allow access to anyone who can prove they have the corresponding private key.
相关标签: 效率