linux基于密钥的认证

生成密钥对儿:

[root@Ams ~]# ssh-keygen -t rsa

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa): 

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:

67:37:f3:cb:90:37:b7:83:19:27:e6:85:4e:e9:68:ec root@Ams

The key's randomart image is:

+–[ RSA 2048]—-+

|                 |

|                 |

|                 |

|                 |

|        S o + o  |

|         o . % o |

|          . X @ .|

|           + X =.|

|          oE  o..|

+—————–+

[root@Ams ~]# ls .ssh/

id_rsa  id_rsa.pub  known_hosts

[root@Ams ~]#

把公钥传输至远程服务器对应用户的家目录:

[root@Ams ~]# ssh-copy-id -i .ssh/id_rsa.pub root@192.168.1.117

root@192.168.1.117's password: 

Now try logging into the machine, with "ssh 'root@192.168.1.117'", and check in:

  .ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

[root@Ams ~]#

现在可以直接登录了:

[root@Ams ~]# ssh root@192.168.1.117

Last login: Sun Jul 31 22:56:04 2016 from 192.168.1.115

[root@bluee ~]#

执行命令也不需要输入密码了。将来集群就需要这样认证:

[root@Ams ~]# ssh root@192.168.1.117 'ifconfig'

eth0      Link encap:Ethernet  HWaddr 00:0C:29:C1:45:55  

          inet addr:192.168.1.117  Bcast:192.168.1.255  Mask:255.255.255.0

          inet6 addr: fe80::20c:29ff:fec1:4555/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:80321 errors:0 dropped:0 overruns:0 frame:0

          TX packets:62829 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000 

          RX bytes:76646060 (73.0 MiB)  TX bytes:6192366 (5.9 MiB)

lo        Link encap:Local Loopback  

          inet addr:127.0.0.1  Mask:255.0.0.0

          inet6 addr: ::1/128 Scope:Host

          UP LOOPBACK RUNNING  MTU:65536  Metric:1

          RX packets:980 errors:0 dropped:0 overruns:0 frame:0

          TX packets:980 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:0 

          RX bytes:97916 (95.6 KiB)  TX bytes:97916 (95.6 KiB)

[root@Ams ~]#

2016-08-01

原创文章,作者:mississippi,如若转载,请注明出处:http://www.178linux.com/27071

(0)
mississippimississippi
上一篇 2016-08-02 10:56
下一篇 2016-08-02 10:58

相关推荐

  • linux发展史

    Linux 发展史 说明 此前对linux认识模糊一知半解,近期通过学习将自己对于linux的发展总结一下方便大家日后的学习。那Linux是目前一款非常火热的开源操作系统,可是linux是什么时候出现的,又是因为什么样的原因被开发出来的呢。以下将对linux的发展历程进行详细的讲解。    目录 一、Linux发展背景 二、UINIX的诞…

    Linux干货 2016-10-14
  • CentOS6.8启动卡死在开机进度条

    不知道什么原因CentOS6.8开机的时候卡在进度条一直进不去。就是下面的画面 在这个画面下面也看不到什么原因,果断F5切换至有显示开机进程的界面 看到了上述的错误提示:invalid user :'root' root是无效的root这是什么鬼? 接下来重新开机,进入到救援模式 开机的时候快速按一下ESC,进入到CD启动,然后选择救援模…

    Linux干货 2016-12-08
  • tar,cpio,rpm,yum的使用详解(适合初学者)

    基于linux下的tar包管理和yum源配置 友情提示:对于这些实际操作的,还是需要进行手工的尝试,由于这几个对于包管理的是比较常用和实用的, 所以,一定要熟练使用。 1.tar tar是对于系统中文件,目录等进行打包,解包的工具。tar也可以对文件进行打包存放到别的目录下, 所以在很早的时候,一些老的工程师经常使用tar对文件进行备份。很大程度上,所谓的t…

    Linux干货 2016-08-21
  • Linux下的find命令详解

    Linux下的find命令详解 在linux下有两种查找符合条件文件的命令,是locate和find。我们来说说find这个命令。 find: 实时查找工具,遍历查找指定路径下的所有的文件来找到符合条件的文件。 特点:查找文件比locate速度略慢,查找文件很精确,并且是实时进行查找的。 使用方法:find [OPTIONS] [查找起始路径] [查找条件]…

    Linux干货 2018-03-20
  • ntp时间服务器搭建实例

    ntp时间服务器采用stratum分级架构来处理时间同步;举例说明:你搭建了一台ntp服务器,然后同步的server为stratum-1,你的ntp则为stratum-2,你的下级ntp则为tratum-3。依此类推,最多为15层。 1.ntp server安装: [root@localhost ~]# yum -y …

    Linux干货 2015-11-10