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

相关推荐

  • 计算机的组成

        计算机组成(computer composition)指的是系统结构的逻辑实现,包括机器机内的数据流和控制流的组成及逻辑设计等。 计算机组成的任务是在指令集系统结构确定分配给硬件系统的功能和概念结构之后,研究各组成部分的内部构造和相互联系,以实现机器指令集的各种功能和特性。这种联系包括各功能部件的内部和相   &nbsp…

    2017-03-26
  • 程序包的编译安装

    程序包的编译安装     程序包的编译安装是比较重要的内容,在之后的网络知识以及服务的配置等学习方面也发挥着重要作用,是我们的必备技能。 一、杂项知识整理 1、which –skip-alias:跳过别名,直接查看原命令 [root@localhost ~]# which –…

    Linux干货 2016-08-24
  • 文本处理工具

    一、文本处理工具的分类:     查看全部内容:more、less、cat、tac、rev     截取文件内容:head 、tail     抽取文件内容:cut     抽取关键字:grep、eg…

    Linux干货 2016-08-08
  • 进程管理,计划任务(2)

    二、作业管理     Linux的作业控制         前台作业:通过终端启动,且启动后一直占据终端;         后台作业:可通过终端启动,但启动后即…

    Linux干货 2016-09-18
  • N25-第九周博客作业

    1、写一个脚本,判断当前系统上所有用户的shell是否为可登录shell(即用户的shell不是/sbin/nologin);分别这两类用户的个数;通过字符串比较来实现; #!/bin/bash # 统计登录用户和非登陆用户的个数 # author: han declare -i loginnum=0 declare -i nologinnum=0 whil…

    Linux干货 2017-02-24
  • Linux发展史

    摘要:Linux无处不在的存在于我们的周围,家庭、公司、学校等等。现在的Linux已经从最初示很少的一段代码,发展成全世界应用范围最广的操作系统。本文将为大家展现Linux的发展史。 一、Linux的是什么       Linux是一套可以免费使用和自由传播的类Unix操作系统操作系统,是一个基于POSIX和UNIX的多用户、多…

    Linux干货 2016-10-18