SSH配置自动登陆的一个小细节

举报
黄生 发表于 2020/07/31 14:36:09 2020/07/31
3.7k+ 1 0
【摘要】 有机器A,要登陆机器B使用SSH登陆,B提示A输入用户名、密码,进行验证这是一个互动的过程,需要输入用户名和密码如果有一个场景,需要自动认证,这时可配置RSA认证来达到目的A对B说,我是我,让我进来吧,B说,怎么证明A说,看这是我私钥加密的数据,你用我公布的公钥解密,解得开就能证明配置过程:A上生成RSA密钥对,私钥自己留着不能示人,公钥可公布,给B一份。ssh-keygen -t rsa即...

有机器A,要登陆机器B

使用SSH登陆,B提示A输入用户名、密码,进行验证

这是一个互动的过程,需要输入用户名和密码

如果有一个场景,需要自动认证,这时可配置RSA认证来达到目的

A对B说,我是我,让我进来吧,B说,怎么证明

A说,看这是我私钥加密的数据,你用我公布的公钥解密,解得开就能证明

配置过程:

  1. A上生成RSA密钥对,私钥自己留着不能示人,公钥可公布,给B一份。ssh-keygen -t rsa即可生成。

  2. 生成的文件,1是id_rsa 这是私钥文件,默认权限是600. 2是id_rsa.pub这是公钥,默认权限是644

  3. A将公钥内容提供给B,B做配置。B建立authorized_keys文件,放入A提供的公钥

  4. 这里就是要说的小细节了。authorized_keys如果新建,默认权限是664. 必须修改为644. 就是rw-r--r--

  5. A直接登陆B成功,不在提示输入用户名和密码。因为默默的他们已通过RSA密钥对认证了身份。

【声明】本内容来自华为云开发者社区博主,不代表华为云及华为云开发者社区的观点和立场。转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息,否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

作者其他文章

评论(1

抱歉,系统识别当前为高风险访问,暂不支持该操作
  • 作者头像

    黄生2022/07/04 06:25:081楼举报回复

    第3步:A将公钥内容提供给B,B做配置。B建立authorized_keys文件,放入A提供的公钥
    ssh-copy-id了解一下:

    ssh-copy-id is a script that uses ssh(1) to log into a remote machine (presumably using a login password, so password authentication should be enabled, unless you've done some clever use of multiple identities).  It assembles a list of one or more fingerprints (as described below) and tries to log in with each key, to see if any of them are already installed (of course, if you are not using ssh-agent(1) this may result in you being repeatedly prompted for pass-phrases).  It then assembles a list of those that failed to log in, and using ssh, enables logins with those keys on the remote server.  By default it adds the keys by appending them to the remote user's ~/.ssh/authorized_keys (creating the file, and directory, if necessary).  It is also capable of detecting if the remote system is a NetScreen, and using its ‘set ssh pka-dsa key ...’ command instead.

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。