一、生成密钥对(两种方式)并配置

方式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)配置私钥

  1. 下载私钥到本地机器

    [root@iZwz9catu2mrq92b07d1d0Z ~]# sz keys_root 
  2. 启动Xshell
  3. 工具(Tools)
  4. 用户密钥管理者(User Key Manager)
  5. 导入已下载的 keys_root 文件(Import)
  6. 配置完成

方式2:使用Xshell生成并配置

  1. 启动Xshell
  2. 工具
  3. 新建用户密钥生成向导(New User Key Wizard)
  4. 按步骤选择下一步
  5. 输入密钥名称和私钥密码后选择下一步
  6. 密钥对生成成功,此时私钥已自动导入到Xshell中,需要我们手动保存公钥到本地机器
  7. 上传已保存的公钥文件到服务器并配置在用户的authorized_keys文件中

二、通过密钥登录服务器

  1. 新建会话,填写名称、主机等信息
  2. 选择左侧栏目用户身份验证,右侧方法选择Public Key,填写用户名,选择对应的用户密钥并填写密钥的密码,点击确定
  3. 连接会话

附录

[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密钥登录的更多相关文章

  1. SSH密钥登录让Linux VPS/服务器更安全

    查看 /var/log 登录日志文件,突然发现服务器被人扫描端口在进行暴力攻击 平常登录服务器,都是使用用户密码登录,看来这样的做法并不安全,不得不关闭密码登录了. 总结了一个putty使用密钥自动登 ...

  2. centos6.7版本下配置ssh密钥登录

    需要提前说明的是我使用的系统是centos6.7的版本. 1.我使用的是Putty登录 #ssh-keygen (生成公钥和私钥的命令) 回车之后会提示密钥要存放的目录,默认的目录是当前目录下的.ss ...

  3. ssh密钥登录及远程执行命令

    以192.168.1.104作为客户机 以192.168.1.103作为服务器 使用密钥登录 创建密钥对 在SSH客户机创建用户秘钥对 ssh-keygen -t rsa 之后全回车即可 将会在~/. ...

  4. SSH 密钥登录 SecureCRT

    https://www.qcloud.com/doc/product/213/2036 1.3. 使用SecureCRT登录 1.3.1. 复制公钥 登录腾讯云控制台,点击[云服务器]-[SSH密钥] ...

  5. fail2ban软件 +ssh密钥登录

    fail2ban可以监视你的系统日志,然后匹配日志的错误信息(正则式匹配)执行相应的屏蔽动作(一般情况下是调用防火墙屏蔽),如:当有人在试探你的SSH.SMTP.FTP密码,只要达到你预设的次数,fa ...

  6. CentOS6.9下ssh密钥登录配置步骤(免密码登录)和ssh-keygen 命令常用参数

    密钥登录步骤(免密码登录)ssh登录提供两种认证方式:口令(密码)认证方式和密钥认证方式.其中口令(密码)认证方式是我们最常用的一种,出于安全方面的考虑,介绍密钥认证方式登录到linux/unix的方 ...

  7. Debian9.5下ssh密钥登录配置步骤(免密码登录)和ssh-keygen 命令常用参数

    密钥登录步骤(免密码登录)ssh登录提供两种认证方式:口令(密码)认证方式和密钥认证方式.其中口令(密码)认证方式是我们最常用的一种,出于安全方面的考虑,介绍密钥认证方式登录到linux/unix的方 ...

  8. Centos7.5使用SSH密钥登录

    12.1.查看操作系统版本 # cat /etc/redhat-release CentOS Linux release 7.5.1804 (Core) 12.2.在服务器端创建密钥 # ssh-ke ...

  9. SSH 密钥登录

    一.什么是SSH? 简单说,SSH是一种网络协议,用于计算机之间的加密登录. 如果一个用户从本地计算机,使用SSH协议登录另一台远程计算机,我们就可以认为,这种登录是安全的,即使被中途截获,密码也不会 ...

随机推荐

  1. Iframe父子窗口之间的跨域事件调用和传值

    实现方案1:location.hash传值 父页面:parent.html(所在域:www.parent.com) 子页面:child.html(所在域:www.child.com) 要实现父子页面双 ...

  2. 容器中使用iptables报错can't initialize iptables table Permission denied (you must be root)

    背景 在docker容器中部署了一微服务,该服务需要docker push镜像到docker registry.因此,docker容器中需要安装docker服务.但在启动容器的时候,却报错: can' ...

  3. 基于FFMpeg的C#录屏全攻略

    最近负责一个录屏的小项目,需要录制Windows窗口内容并压缩保存到指定文件夹,本想使用已有的录屏软件,但是本着学习的态度去探索了FFMpeg,本文主要介绍基于FFMpeg开源项目的C#录屏软件开发. ...

  4. JavaScript 开发人员需要知道的简写技巧

    本文来源于多年的 JavaScript 编码技术经验,适合所有正在使用 JavaScript 编程的开发人员阅读. 本文的目的在于帮助大家更加熟练的运用 JavaScript 语言来进行开发工作. 文 ...

  5. ASP.NET Core 2.0 in Docker on Windows Container

    安装Docker for Windows https://store.docker.com/editions/community/docker-ce-desktop-windows 要想将一个ASP. ...

  6. mysql安装教程以及配置快捷方式

    1.首先双击exe 3.Next 安装过程省略.... Win+r 然后输入:cmd 打开dos窗口后: 输入: mysql -uroot -p你设置的密码 案例:mysql -uroot -proo ...

  7. Mysql 用户,权限管理的几点理解。

    前两天项目数据库要移植到mysql,为此临时抓了几天很久没用的mysql. 公司的数据库比较简单,从oracle迁移到mysql很简单,但是,中间的权限管理让我感觉既简单又复杂..简单是因为网上关于m ...

  8. 快速部署Telegraf & Influxdb

    是什么? Telegraf 是一个用 Go 编写的代理程序,可收集系统和服务的统计数据,并写入到 InfluxDB 数据库.Telegraf 具有内存占用小的特点,通过插件系统开发人员可轻松添加支持其 ...

  9. python 模块的概念介绍

    模块 模块:本质就是一个.py文件分为三部分:内置模块.第三方模块,自定义模块 模块: 顶层文件 python模块python模块可以将代码量较大的程序分割成多个有组织的.彼此独立但又能互相交互的代码 ...

  10. python去除读取文件中多余的空行

    今天在写登录程序练习的时候,黑名单文件中多了几行空行.导致运行的时候报错:IndexError: list index out of range 代码 brackData = open(brackDa ...