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

相关推荐

  • shell脚本编程的执行语句

    顺序执行     从上到下逐条执行命令,执行完所有命令及退出。 选择执行     (1)&&,||     &&:代表and,&&左侧为真右侧则执行     ||:代表or…

    Linux干货 2016-08-24
  • 一.Liunx博客-2016年7月19日文件系统类型、分区类型

    格式说明: 操作 概念 命令 说明及举例 一.文件系统类型、分区类型 转换磁盘文件系统命令 convert e: /fs:ntfs su – root 切换到root用户 linux根 /windows根 \ cd \ home:用户root:usr:tmp:临时文件dev:硬件设备 IDE /dev/hda…

    Linux干货 2016-08-23
  • yum用法第一篇-简介及常见用法使用总结

    一、简介     yum( 全称为:Yellow dog Updater, Modified),是红帽(RedHat)家族(RedHat、Fedora、CentOS)中的前端shell的软件包管理器,主要基于对RPM包的管理,能够根据配置文件(类似于svn资源库配置文件)从指定的服务器自动下载RPM包进行安装,其最大的优势就是可…

    Linux干货 2015-09-22
  • systemd

    systemd 启动流程:POST -> BIOS -> MBR bootloader -> kernel 临时根 -> 根文件系统 -> init init 能够管理、控制init进程的模块,就是init系统 能够让系统在用户预定义的级别下运行 设备管理器: sysvinit : CentOS 5 第一个广泛应用的init系统…

    Linux干货 2017-05-21
  • 利用 yum 查找某个命令属于哪个包

    当我们在安装一个不熟悉的命令是,会遇到个问题:Error: Nothing to do 而你又不知道该命令的是属于哪个rom包,莫慌~我们可以借助一个叫yum的基于rpm的软件包管理器。 以 dig 这个命令为例,当我安装它时会出现如下情况  [root@localhost ~]# yum install dig  Loaded plug…

    Linux干货 2016-03-27
  • 通过Xshell 5连接VirtualBox的centos

    环境:VirtualBox  centos6.5 1、使用VirtualBox Host-Only Network模式 2、打开宽带连接,设置属性,选择VirtualBox Host-Only Network共享。(在这里虚拟机centos的IP地址是自动获得,并且可以上网。) 3、虚拟机centos需要     关闭防火墙 :…

    Linux干货 2015-11-07