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)
上一篇 2016-08-02 10:56
下一篇 2016-08-02 10:58

相关推荐

  • 关于软硬链接那些事儿

           小编这周接触到了链接,那么重点来了,啥是链接呢小编觉得链接简单来说就是一种共享的方式,比如我们去逛超市,超市的入口就是‘链接’。在Linux中,链接又分为软连接和硬链接,想要了解他俩,就得先了解几个基本概念。 一:Inode       我们知道文件包含数据和元数据,它的数据…

    Linux干货 2017-07-22
  • 请使用命令行展开功能来完成以下练习

    (1)、创建/tmp目录下的:ac, ad, bc, bd ]# mkdir -p /tmp/{a,b}_{c,d} 或者: ]# touch /tmp/{a,b}_{c,d} (2)、创建/tmp/mylinux目录下的: ]# mkdir -pv /tmp/mylinux/{bin,boot/gtub,dev,etc/{rc.d/init.d,sysco…

    Linux干货 2016-11-06
  • Linux 第四天: (07月28日) Linux文件管理

    Linux 第四天: (07月28日) Linux文件管理         rootfs 根目录文件系统 root filesystemLSB  Linux Standard BaseFHS 文件系统分层结构 Filesystem Hierarchy Standard     蓝色表示 目…

    Linux干货 2016-08-08
  • 用户管理相关

    安全3A:     资源分配:       authentication:认证       authorization 授权       accouting|audition 审计 用户分为(centos7):   管理员:root 0 &…

    Linux干货 2017-02-25
  • linux系统自动化安装和selinux

    系统自动化安装: Anaconda 安装系统分成三个阶段:  安装前配置阶段安装过程使用的语言键盘类型安装目标存储设备Basic Storage :本地磁盘特殊设备:iSCSI设定主机名配置网络接口时区管理员密码x设定分区方式及MBR 的安装位置创建一个普通用户选定要安装的程序包 创建引导光盘:#cp /media/cdrom/isoli…

    Linux干货 2017-04-06
  • 第3周作业

    一、列出当前系统上的所有已经登录的用户的用户名 [root@bogon tmp]# who | cut -d ” ” -f1 | sort -urootwing[root@bogon tmp]# who | cut -d ” ” -f1 | uniqrootwing 二、取出最后登录到当前系统的用户相关信息 […

    Linux干货 2017-07-25