目前很多服务(ceph,openstack等)都需要用到SSH使用ssh-key进行登录,而不能使用密码进行登录。

下面是配置步骤:

一、在SSH Client生成ssh key pair

root@ceph01:~# ssh-keygen
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:
1e:f1:c6:c5:c4:8e:e0:b3:ed:9f:2c:::ce:8a:0d root@ceph01
The key's randomart image is:
+--[ RSA ]----+
| .. |
| . o. |
| ... oo |
| . ++... |
| o oS++ |
| E o.ooo |
| + . .o . |
| . o o. . |
| o+ |
+-----------------+

二、复制id_rsa.pub内容到 SSH Server 用户的.ssh/authorized_keys 中

root@ceph01:~# ssh-copy-id ceph02
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@ceph02's password: Number of key(s) added: Now try logging into the machine, with: "ssh 'ceph02'"
and check to make sure that only the key(s) you wanted were added.

查看SSH Server 用户的.ssh/authorized_keys文件内容

root@ceph02:~/.ssh# cat authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC1hXDFOCI0hdsZlvuP9FGLnCd6k6yR51T6WN4+Wr/shJlY6ymcxde2hwBhiGowvKNbhpVA3EHUxtV0W9YH742ymTmUCVBCuGd2zUwB36AR9aiQGFwSd8vulqaybirpsic9iZ4d83cGjdJwSQg5mGhxZpzi4qD8yygdEDkTcczIFj+9zh5BCIlsZXFHU8044wIKBAbp2YvrsCW0L81XvVJZo3OJxggbUYlMhXcws99U7q2JcBUKv9IQYjar9GyYh4DNlllDs56sfR6SDtuT1O6NOtKSCc6jxCpf7EmxgBXIeYQiSUKnwDo3CE4FmvFsmTlkFUkOluJIRGUTbkokw5tJ root@ceph01

三、在SSH Server上修改sshd_config配置文件

Port
# Use these options to restrict which interfaces/protocols sshd will bind to
#ListenAddress ::
#ListenAddress 0.0.0.0
Protocol
# HostKeys for protocol version
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
#Privilege Separation is turned on for security
UsePrivilegeSeparation yes # Lifetime and size of ephemeral version server key
KeyRegenerationInterval
ServerKeyBits # Logging
SyslogFacility AUTH
LogLevel INFO # Authentication:
LoginGraceTime
PermitRootLogin yes
StrictModes yes RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile %h/.ssh/authorized_keys # Don't read the user's ~/.rhosts and ~/.shosts files
IgnoreRhosts yes
# For this to work you will also need host keys in /etc/ssh_known_hosts
RhostsRSAAuthentication no
# similar for protocol version
HostbasedAuthentication no
.
.
.

四、验证

root@ceph01:~# ssh root@ceph02
Welcome to Ubuntu 14.04 LTS (GNU/Linux 3.13.--generic x86_64) * Documentation: https://help.ubuntu.com/ System information as of Wed Jan :: CST System load: 0.0 Processes:
Usage of /: 3.7% of .95GB Users logged in:
Memory usage: % IP address for eth0: 192.168.20.178
Swap usage: % Graph this data and manage this system at:
https://landscape.canonical.com/ packages can be updated.
updates are security updates. New release '16.04.1 LTS' available.
Run 'do-release-upgrade' to upgrade to it. Last login: Wed Jan :: from 192.168.20.116
root@ceph02:~#

最新文章

  1. php实现文件上传与下载(中)
  2. magento后台使用POST表单时,要使用必要参数form_key才能正常通讯
  3. 事件类型: 错误 事件来源: Service Control Manager 事件种类: 无 事件 ID: 7000
  4. sharepoint 2013 安装配置PowerView
  5. 简述TVS是的命名和封装
  6. (hdu step 7.1.5)Maple trees(凸包的最小半径寻找掩护轮)
  7. 第一百二十五节,JavaScript,XML
  8. 1)C语言简介(C自考学习)
  9. java列表数据基本操作
  10. Jmeter应用-接口测试
  11. javascript 之 继承
  12. mysql 计算两点经纬度之间的直线距离(具体sql语句)
  13. linux系统状态检测命令
  14. Mysql简单入门
  15. Codeforces Beta Round #14 (Div. 2) A. Letter 水题
  16. 第九次CSP第四题 - 压缩编码
  17. Xcode模拟器的一些快捷键
  18. SpringAOP 通知(advice)
  19. atcoder ARC092 D - Two Sequences 二分 & 二进制
  20. OpenCV代码提取:dft函数的实现

热门文章

  1. Ionic 取消自带动画效果
  2. 强大的find命令
  3. python在linux中输出带颜色的文字的方法
  4. http 状态吗
  5. 使用Nexus管理Maven仓库时,上传带依赖的第三方jar
  6. Martin Fowler’s Active Record design pattern.
  7. cron_action
  8. BufferedReader.mark()函数注意事项
  9. Django 之 序列化
  10. 什么是 XML Schema(转)