美文网首页
ssh公钥认证免密登陆

ssh公钥认证免密登陆

作者: CUFFS | 来源:发表于2017-10-12 14:33 被阅读155次

参考文章

http://www.cnblogs.com/Impulse/p/3974480.html #公钥私钥解释
http://www.cnblogs.com/hukey/p/6248468.html #SSH登录方式
http://www.ruanyifeng.com/blog/2011/12/ssh_remote_login.html

假设A服务器需要登陆到B服务器

  • 在A服务器执行ssh-keygen命令生成公钥和私钥
  • 在A 服务器执行ssh-copy-id user@host命令把A的公钥复制到B服务器的$HOME/.ssh/authorized_keys文件中

在A服务器生成公钥和私钥

~/.ssh # ssh-keygen 
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
/root/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:fXQ6jYk6D7FihPEjRdIQ1bD9bXJ9daH8nLyxHzrkyII root@d9b873171c1a
The key's randomart image is:
+---[RSA 2048]----+
|    +=+o       . |
|     o.o.   . . .|
|    . o .   .o. o|
|     =   o + B+ +|
|    o + S = X o*.|
|     o . + = o .+|
|      o * . +  + |
|     . E = o o. o|
|          o  .. .|
+----[SHA256]-----+
~/.ssh # 
~/.ssh # ls -la
total 16
drwx------    1 root     root            38 Sep 26 10:57 .
drwx------    1 root     root           124 Oct 12 14:22 ..
-rw-------    4 root     root           399 Sep 26 10:42 authorized_keys
-rw-------    1 root     root          1679 Oct 12 14:27 id_rsa
-rw-r--r--    1 root     root           399 Oct 12 14:27 id_rsa.pub
-rw-r--r--    4 root     root           348 Sep 26 10:42 known_hosts
~/.ssh # 

把A服务器的公钥给B服务器

~/.ssh # ssh-copy-id dataagg@192.168.100.196
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
expr: warning: '^ERROR: ': using '^' as the first character
of a basic regular expression is not portable; it is ignored
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
dataagg@192.168.100.196's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'dataagg@192.168.100.196'"
and check to make sure that only the key(s) you wanted were added.

~/.ssh # 
# B服务器dataagg账户下面的认证文件
[root@localhost .ssh]# ls -la
总用量 4
drwx------. 2 dataagg dataagg  29 10月 12 14:30 .
drwx------. 3 dataagg dataagg  74 10月 12 14:30 ..
-rw-------. 1 dataagg dataagg 399 10月 12 14:30 authorized_keys
[root@localhost .ssh]# 

验证是否能免密登陆

~/.ssh # ssh dataagg@192.168.100.196
[dataagg@localhost ~]$  #登陆成功

相关文章

  • ssh nfs dhcp dns

    一.ssh(免密登陆) A ----> B : 1.A生成私钥公钥对 ---- ssh-keygen -t rsa...

  • ssh公钥认证免密登陆

    参考文章 http://www.cnblogs.com/Impulse/p/3974480.html #公钥私钥解...

  • SSH的总结

    ssh的相关总结ssh登陆的过程非对称加密RSA登陆过程免密登陆linux相关文件及操作公钥与秘钥的保存格式用密码...

  • 90729-Centos 7 ssh 免密登陆配置及登陆失败排

    CentOS 7 ssh 免密登陆 基础信息 ssh 配置 生成 rsa 信息 将生成的 公钥信息发送到目标机器 ...

  • 局域网中服务器群配置ssh免密

    笔者以前配置ssh免密登陆,基本两步就可以了, ssh-keygen删除密钥对, ssh-copy-id公钥复...

  • SSH免密码登陆

    ssh免密码登陆 生成密钥公钥命令:ssh-keygen -t rsa位置是当前目录 生成内容公钥:.ssh/id...

  • SSH公钥 免密登陆

    生成 SSH 公钥 如前所述,许多 Git 服务器都使用 SSH 公钥进行认证。 为了向 Git 服务器提供 SS...

  • ssh-keygen

    ssh-keygen用来生成ssh公钥认证所需的公钥和私钥文件。 ssh秘钥登录特点:1.安全;2.免输密码。对于...

  • 配置ssh免登陆

    1、生成ssh免登陆密钥 2、将公钥拷贝到要免登陆的机器上

  • 免密登录Linux

    免密登录Linux 将SSH公钥上传到Linux服务器,

网友评论

      本文标题:ssh公钥认证免密登陆

      本文链接:https://www.haomeiwen.com/subject/clznyxtx.html