Linux ssh 不需要输入密码的方法
2015-12-05 13:21
441 查看
采用证书的方法可以解决ssh不需要输入密码的问题。
本文采用CentOS的操作系统,创建SSH的key,并在两台或多台机器间实现信任。从而实现SSH登录不需要输入密码的功能。
首先,在一台机器上创建SSH Key:
[root@mysql-ha2 ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
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:
e1:9b:9a:b8:4d:ea:2c:e7:0c:49:bd:a7:47:fa:b4:4b root@mysql-ha2
The key's randomart image is:
+--[ RSA 2048]----+
| |
| |
| . |
| . . . |
| . . S |
| . . .. o |
| o .oE o |
| .+oX.+ |
| =X+B. |
+-----------------+
此时可以在/root/.ssh目录下看到两个文件:
-rw-------. 1 root root 1675 Dec 5 05:02 id_rsa
-rw-r--r--. 1 root root 396 Dec 5 05:02 id_rsa.pub
复制Key到另外一台机器上,使登录这台机器不输入密码:
[root@mysql-ha2 .ssh]# ssh-copy-id -i id_rsa.pub root@10.1.1.4
测试,发现登录ssh 10.1.1.4不需要密码。
把id_rsa和id_rsa.pub复制到10.1.1.4上,在10.1.1.4上做同样的ssh-copy-id的动作,可以使双向ssh登录不需要密码。
且采用的是相同的ssh key。
本文采用CentOS的操作系统,创建SSH的key,并在两台或多台机器间实现信任。从而实现SSH登录不需要输入密码的功能。
首先,在一台机器上创建SSH Key:
[root@mysql-ha2 ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
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:
e1:9b:9a:b8:4d:ea:2c:e7:0c:49:bd:a7:47:fa:b4:4b root@mysql-ha2
The key's randomart image is:
+--[ RSA 2048]----+
| |
| |
| . |
| . . . |
| . . S |
| . . .. o |
| o .oE o |
| .+oX.+ |
| =X+B. |
+-----------------+
此时可以在/root/.ssh目录下看到两个文件:
-rw-------. 1 root root 1675 Dec 5 05:02 id_rsa
-rw-r--r--. 1 root root 396 Dec 5 05:02 id_rsa.pub
复制Key到另外一台机器上,使登录这台机器不输入密码:
[root@mysql-ha2 .ssh]# ssh-copy-id -i id_rsa.pub root@10.1.1.4
测试,发现登录ssh 10.1.1.4不需要密码。
把id_rsa和id_rsa.pub复制到10.1.1.4上,在10.1.1.4上做同样的ssh-copy-id的动作,可以使双向ssh登录不需要密码。
且采用的是相同的ssh key。
相关文章推荐
- Linux下根目录下文件挂载机制
- Linux虚拟文件系统VFS
- LINUX 安全运维 (六)
- 解决yum安装软件报Couldn't resolve host 'mirrorlist.centos.org问题
- linux 程序调试
- 看我linux(ubuntu)下的64位编译器编译32位程序
- 源码分析:动态分析 Linux 内核函数调用关系
- linux下的系统调用函数到内核函数的追踪
- CentOS学习日记:PostgreSQL篇
- Linux_FTP服务器
- #Linux学习笔记# Linux系统查看文件内容的命令
- 在Linux下创建分区和文件系统的方法详解
- Linux Is Not Matrix——repo浅解
- Linux串口驱动(8250)的编写与调试
- Linux_Index
- Linux init 系列一 System V风格
- Linux 内存管理子系统
- 第一章 Linux系统简介
- 如何在CentOS 7安装Node.js
- Linux本地socket通信--AF_UNIX