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

相关推荐

  • RAID简述和Linux软RAID配置

    RAID简述和Linux软RAID配置 PS:仅为课程练习,原理和配置可能有误,仅供参考,谢谢; 1.RAID功能简述     RAID,全称(Redundant Arrays of Inexpensive Disk或Redundant Arrays of Independent Disk),现在一般多用于后面那个称呼,独立磁盘冗余阵列。RAID的基础概念大…

    Linux干货 2016-07-17
  • 常用RAID级别介绍

    RAID是什么         磁盘阵列(Redundant Arrays of Independent Disks,RAID),磁盘阵列是将多个价格便宜的磁盘按照一定的组合方式组成具有高容量的磁盘组,按照不同的组合方式可以达到不同的效果,如:可以提升磁盘的存取效率,可提高磁盘的…

    Linux干货 2016-02-14
  • 管理systemd

    管理systemd init(系统的第一个进程): CentOS 5: SysV initCentOS 6: UpstartCentOS 7: Systemd Systemd:系统启动和服务器守护进程管理器,负责在系统启动或运行时,激活系统资源,服务器进程和其它进程 Systemd新特性: 系统引导时实现服务并行启动 按需启动守护进程 系统状态快照 自动化的…

    Linux干货 2016-09-22
  • linux命令格式,获取帮助及其目录结构简要理解

    我们都知道,一台计算机要是没通电,和一堆废铁没什么区别。那么,通电开机进入系统后,会进入交互界面,等待用户操作,人与计算机交互界面有两种: GUI:图形用户接口。如我们平时使用的Windows  ,linux的X window,有KDE和GOME.   CLI:命令行接口,使用的SHELL类型有bash ,csh,tcshell,zshell等。 …

    2017-09-14
  • 2016-08-12作业

    1、查找/var 目录下属主为root ,且属组为mail 的所有文件 [root@localhost bin]# find /var -user root -group mail /var/spool/mail /var/spool/mail/root   2、查找/var 目录下不属于root 、lp 、gdm 的所有文件 find /var …

    Linux干货 2016-08-15
  • 网络接口配置bonding

    Bonding 就是将多块网卡绑定同一IP地址对外提供服务,可以实现高可用或者负载均衡。当然,直接给两块网卡设置同一IP地址是不可能的。通过bonding,虚拟一块网卡对外提供连接,物理网卡的被修改为相同的MAC地址。 Bonding的工作模式 Mode 0 (balance-rr)     轮转(…

    Linux干货 2016-09-09