ssh密钥登录
一、生成密钥对(两种方式)并配置
方式1:使用ssh-keygen(1)生成并配置
(1)生成密钥对
[root@iZwz9catu2mrq92b07d1d0Z ~]# ssh-keygen -t rsa
Generating public/private rsa key pair. //输入文件名称
Enter file in which to save the key (/root/.ssh/id_rsa): keys_root
//输入私钥加密密码
Enter passphrase (empty for no passphrase):
//再次输入密码
Enter same passphrase again: Your identification has been saved in keys_root.
Your public key has been saved in keys_root.pub.
The key fingerprint is:
f4:f9:::cf::f6:da::6a:b1::4f:dc:: root@iZwz9catu2mrq92b07d1d0Z
The key's randomart image is:
+--[ RSA ]----+
| o+E |
| ..ooo|
| . ..o o+|
| . . .+.*..|
| S ++.+ +.|
| .+o o |
| . . |
| |
| |
+-----------------+ //文件生成成功,keys_root为私钥,keys_root.pub为公钥
[root@iZwz9catu2mrq92b07d1d0Z ~]# ls
keys_root keys_root.pub
(2)配置公钥
//将生成的公钥写入到用户的authorized_keys
[root@iZwz9catu2mrq92b07d1d0Z ~]# echo -e '#this is keys_root' >> ~/.ssh/authorized_keys ; cat ~/keys_root.pub >> ~/.ssh/authorized_keys [root@iZwz9catu2mrq92b07d1d0Z ~]# cat ~/.ssh/authorized_keys
#this is keys_root
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAyhp9SBxas8Nmwdi4dQfOuUULpMGRnGEFopU2DXhSF+PE/s80xrVS31Ycd5o4gU3iehKx2vo4OEB2lYZ2JCfptTc59HAj+Qwqh7i5S4YQuX/+31GkY+s8XKFR4QgH1ubQt9feU2cagfG1f+wWRsa0YtefE67Kjv6OZuKuA2bOdrAH4mzV1m71iLMUZYgaEnfJExXj2lbPAXRqCV+tdIj9h0jxhB5pQXsZ3NE38D22WYNKO4Sy8odfE7Oby1I0Emm8Uhiwqgx91HP22iY/WqzZOxeKZPF17CPWr9cChaPh9/DXM1Wd8KDCg33MO6hbpqAwh7iEughndXly0FY0oZNKnQ== root@iZwz9catu2mrq92b07d1d0Z
(3)配置私钥
- 下载私钥到本地机器
[root@iZwz9catu2mrq92b07d1d0Z ~]# sz keys_root
- 启动Xshell
- 工具(Tools)
- 用户密钥管理者(User Key Manager)
- 导入已下载的 keys_root 文件(Import)
- 配置完成
方式2:使用Xshell生成并配置
- 启动Xshell
- 工具
- 新建用户密钥生成向导(New User Key Wizard)
- 按步骤选择下一步
- 输入密钥名称和私钥密码后选择下一步
- 密钥对生成成功,此时私钥已自动导入到Xshell中,需要我们手动保存公钥到本地机器
- 上传已保存的公钥文件到服务器并配置在用户的authorized_keys文件中
二、通过密钥登录服务器
- 新建会话,填写名称、主机等信息
- 选择左侧栏目用户身份验证,右侧方法选择Public Key,填写用户名,选择对应的用户密钥并填写密钥的密码,点击确定
- 连接会话
附录
[root@iZwz9catu2mrq92b07d1d0Z ~]# man ssh
1.ssh-keygen命令介绍
The user creates his/her key pair by running ssh-keygen(1). This stores the private key in ~/.ssh/identity (protocol 1), ~/.ssh/id_dsa (protocol 2 DSA), ~/.ssh/id_ecdsa (protocol 2
ECDSA), or ~/.ssh/id_rsa (protocol 2 RSA) and stores the public key in ~/.ssh/identity.pub (protocol 1), ~/.ssh/id_dsa.pub (protocol 2 DSA), ~/.ssh/id_ecdsa.pub (protocol 2 ECDSA), or
~/.ssh/id_rsa.pub (protocol 2 RSA) in the user’s home directory. The user should then copy the public key to ~/.ssh/authorized_keys in his/her home directory on the remote machine.
The authorized_keys file corresponds to the conventional ~/.rhosts file, and has one key per line, though the lines can be very long. After this, the user can log in without giving
the password.
注:每个用户都拥有自己的 authorized_keys
2.authorized_keys文件介绍
~/.ssh/authorized_keys
Lists the public keys (RSA/ECDSA/DSA) that can be used for logging in as this user. The format of this file is
described in the sshd(8) manual page. This file is not highly sensitive, but the recommended permissions are
read/write for the user, and not accessible by others.
注:建议文件权限对拥有者为读写权限,其他用户无权限
转载请注明:http://www.cnblogs.com/cjh-notes/p/7865513.html
ssh密钥登录的更多相关文章
- SSH密钥登录让Linux VPS/服务器更安全
查看 /var/log 登录日志文件,突然发现服务器被人扫描端口在进行暴力攻击 平常登录服务器,都是使用用户密码登录,看来这样的做法并不安全,不得不关闭密码登录了. 总结了一个putty使用密钥自动登 ...
- centos6.7版本下配置ssh密钥登录
需要提前说明的是我使用的系统是centos6.7的版本. 1.我使用的是Putty登录 #ssh-keygen (生成公钥和私钥的命令) 回车之后会提示密钥要存放的目录,默认的目录是当前目录下的.ss ...
- ssh密钥登录及远程执行命令
以192.168.1.104作为客户机 以192.168.1.103作为服务器 使用密钥登录 创建密钥对 在SSH客户机创建用户秘钥对 ssh-keygen -t rsa 之后全回车即可 将会在~/. ...
- SSH 密钥登录 SecureCRT
https://www.qcloud.com/doc/product/213/2036 1.3. 使用SecureCRT登录 1.3.1. 复制公钥 登录腾讯云控制台,点击[云服务器]-[SSH密钥] ...
- fail2ban软件 +ssh密钥登录
fail2ban可以监视你的系统日志,然后匹配日志的错误信息(正则式匹配)执行相应的屏蔽动作(一般情况下是调用防火墙屏蔽),如:当有人在试探你的SSH.SMTP.FTP密码,只要达到你预设的次数,fa ...
- CentOS6.9下ssh密钥登录配置步骤(免密码登录)和ssh-keygen 命令常用参数
密钥登录步骤(免密码登录)ssh登录提供两种认证方式:口令(密码)认证方式和密钥认证方式.其中口令(密码)认证方式是我们最常用的一种,出于安全方面的考虑,介绍密钥认证方式登录到linux/unix的方 ...
- Debian9.5下ssh密钥登录配置步骤(免密码登录)和ssh-keygen 命令常用参数
密钥登录步骤(免密码登录)ssh登录提供两种认证方式:口令(密码)认证方式和密钥认证方式.其中口令(密码)认证方式是我们最常用的一种,出于安全方面的考虑,介绍密钥认证方式登录到linux/unix的方 ...
- Centos7.5使用SSH密钥登录
12.1.查看操作系统版本 # cat /etc/redhat-release CentOS Linux release 7.5.1804 (Core) 12.2.在服务器端创建密钥 # ssh-ke ...
- SSH 密钥登录
一.什么是SSH? 简单说,SSH是一种网络协议,用于计算机之间的加密登录. 如果一个用户从本地计算机,使用SSH协议登录另一台远程计算机,我们就可以认为,这种登录是安全的,即使被中途截获,密码也不会 ...
随机推荐
- Babylon.GUI官方文档翻译
Babylon.GUI是一个基于Babylon.js的WebGL库,可以用来在WebGL3D场景中生成交互性UI与动态纹理.相比于html ui,Babylon.GUI的功能较为简化,但使用起来也更加 ...
- Python基础2 编码和逻辑运算符
编码: AscII码 :标准ASCII码是采用7位二进制码来编码的,当用1个字节(8位二进制码)来表示ASCII码时,就在最高位添加1个0. 一个英文字母占一个字节 8位(bit)==一个字节(byt ...
- 开发人员的福音:微软、谷歌、Mozilla将他们所有的web API文档放在同一个地方
Tips 原文作者:Liam Tung 原文地址:Developers rejoice: Microsoft, Google, Mozilla are putting all their web A ...
- C#通过OpenCL调用显卡GPU做高效并行运算
GPU的并行运算能力远超CPU,有时候我们会需要用到超大数据并行运算,可以考虑用GPU实现,这是一篇C#调用GPU进行运算的入门教程. 1: 下载相关的库: https://sourceforge.n ...
- CentOS 升级 Python3 (附带: 一键升级脚本)
升级环境 应用名称 版本 Python 3.5.2 Syatem CentOS 6.7 升级方法 [1]下载 Python 3: wget http://mirrors.s ...
- Linux系统查找
1. which:在当前用户环境变量path指定的路径下查找可执行程序/文件. 特点:(1)只在当前用户环境变量指定的路径下查找: (2)只找出可执行程序/文件的位置: (3)查找速度非常快. 注:使 ...
- LeetCode 561. Array Partition I (数组分隔之一)
Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1 ...
- maven 集成tomcat6,tomcat7
1. maven 集成 tomcat6的配置 maven自带的是tomcat6插件,所以不配置的话也可以,默认tomcat6,8080端口,需要更改端口或者编码方式等,也可以自己再配置一次: < ...
- hbase+springboot+redis实现分页
实现原理: 1.读取hbase数据每页的数据时多取一条数据.如:分页是10条一页,第一次查询hbase时, 取10+1条数据,然后把第一条和最后一条rowkey数据保存在redis中,redis中的k ...
- struts2(四)之输入校验
前言 这个本来是昨天就写好的,但是不知道为什么没有保存成功!但是今天起来再写一遍就当巩固一下知识吧. 一.输入校验概述 在以前我们写一个登录页面时,并没有限制用户的输入,不管用户输入什么,我们都存入数 ...