ssh无密码登录

SSH (Secure SHELL) is a secure opensource network protocol that allows users to log in securely to remote Linux systems and other network devices. In addition, the protocol is used for the transfer of files between Linux systems using Secure copy (SCP) protocol.

SSH(Secure SHELL)是一种安全的开源网络协议,允许用户安全地登录到远程Linux系统和其他网络设备。 此外,该协议还用于使用安全复制(SCP)协议在Linux系统之间传输文件。

Usually, SSH prompts users for passwords before login. However, you can configure SSH Passwordless login to another remote Linux system from your Linux system. This enhances trust and comes in handy in cron jobs that require backup of files remotely using the SCP protocol.

通常,SSH在登录前提示用户输入密码。 但是,您可以将SSH无密码登录配置为从Linux系统登录到另一个远程Linux系统。 这样可以增强信任度,并在需要使用SCP协议远程备份文件的cron作业中派上用场。

In this guide, you will learn how to set up passwordless SSH login using ssh keys to increase trust between two servers.

在本指南中,您将学习如何使用ssh密钥设置无密码SSH登录,以增加两个服务器之间的信任。

搭建环境 (Set up environment)

ssh client      : 66.152.163.19 (Ubuntu 18.04)ssh remote Host : 173.82.2.236  (CentOS 7)

在客户端系统上生成SSH密钥(66.152.163.19) (Generate SSH keys on the client system ( 66.152.163.19 ) )

The first step in setting up a passwordless login is to generate ssh authentication keys in the client system. SSH keys are digital keys that create trust between Linux systems.

设置无密码登录名的第一步是在客户端系统中生成ssh身份验证密钥。 SSH密钥是在Linux系统之间建立信任的数字密钥。

To generate the ssh keys execute the command.

要生成ssh密钥,请执行命令。

$ ssh-keygen

You will be prompted for the file in which to save the key. Hit ‘Enter’ to save to the default location directory ( /root/.ssh)

系统将提示您输入保存密钥的文件。 点击“ Enter”保存到默认位置目录(/root/.ssh)

Enter file in which to save the key (/home/user/.ssh/id_rsa):

Hit Enter.

按下Enter键。

Next, you will be prompted for a passphrase. This we are setting up a passwordless login, hit ‘Enter’ twice to skip.

接下来,将提示您输入密码。 这是我们要设置的无密码登录,按两次“ Enter”以跳过。

Enter passphrase (empty for no passphrase):
Enter same passphrase again:

Hit ‘Enter’ on both occasions.

两次都按下“ Enter”。

The full output is shown below.

完整的输出如下所示。

Sample output

样品输出

The ssh-keygen command generates both public and private ssh keys and stores them in /root/.ssh directory.

ssh-keygen命令生成公共和私有ssh密钥,并将它们存储在/root/.ssh目录中。

To verify run:

验证运行:

ls /root/.ssh

Sample output

样品输出

The public key is denoted by id_rsa.pub.

公钥由id_rsa.pub表示。

The private key is denoted by id_rsa.

私钥由id_rsa表示。

将ssh公钥复制到远程系统(173.82.2.236) (Copying the ssh public key to the remote system (173.82.2.236))

The next step is to copy the public key to the remote Linux server. This will be achieved using the ssh-copy-id command as shown below.

下一步是将公钥复制到远程Linux服务器。 这将使用ssh-copy-id命令来实现,如下所示。

ssh-copy-id remote_username@server_ip_address

In our example, the command will be:

在我们的示例中,命令将为:

ssh-copy-id root@173.82.2.236

You will be asked if you are sure you want to continue connecting. Type yes and hit ‘Enter’

系统将询问您是否确定要继续连接。 输入yes然后按“ Enter”

The authenticity of host '173.82.2.236 (173.82.2.236)' can't be established.
ECDSA key fingerprint is SHA256:U4aOk0p30sFjv1rzgh73uhGilwJ2xtG205QFqzB9sns.
Are you sure you want to continue connecting (yes/no)? yes

Next, you will be prompted for the remote system’s password. Type the password and hit ‘Enter’

接下来,将提示您输入远程系统的密码。 输入密码并点击“ Enter”

root@173.82.2.236's password:Number of key(s) added: 1Now try logging into the machine, with:   "ssh 'root@173.82.2.236'"
and check to make sure that only the key(s) you wanted were added.

The full output is shown below.

完整的输出如下所示。

The ssh public key will be saved at /root/.ssh/authorized_keys file on the remote system.

ssh公钥将保存在远程系统上的/root/.ssh/authorized_keys文件中。

登录到远程系统 (Logging in to the remote system)

Having copied the public ssh key to the remote system, you can now log in without being prompted for a password as shown.

将公用ssh密钥复制到远程系统后,您现在可以登录,而无需提示输入密码,如图所示。

ssh server-ip-address

For our case, this will be:

对于我们来说,这将是:

ssh 173.82.2.236

And that’s how you set up a Passwordless SSH setup from a client Linux system to a remote Linux server.

这就是从客户端Linux系统到远程Linux服务器的无密码SSH设置的方法。

  • Delete the public key from the client system. If you think that the private key is compromised, delete the public key from the remote server and set it up again.从客户端系统中删除公钥。 如果您认为私钥已被破坏,请从远程服务器上删除公钥,然后重新设置。
  • The above SSH command works without giving user id because we are using the root user in both the servers. If you have set up passwordless login for some other user, please provide that in the SSH command too.上面的SSH命令可以在不提供用户ID的情况下工作,因为我们在两个服务器上都使用root用户。 如果您为其他用户设置了无密码登录,请在SSH命令中也提供该密码。

翻译自: https://www.journaldev.com/30301/passwordless-ssh-login

ssh无密码登录

ssh无密码登录_3个简单步骤即可完成无密码SSH登录相关推荐

  1. java创建类的三个步骤_3个简单步骤即可测试Java 8

    java创建类的三个步骤 即将发布的Java 8版本为Java开发人员带来了许多新功能,但是升级时始终存在代码破裂的风险. 我们都记得Java 7出厂时有一系列非常严重的错误 . 当然,我们所有人都可 ...

  2. 3个简单步骤即可测试Java 8

    即将发布的Java 8版本为Java开发人员带来了许多新功能,但是升级时始终存在代码破裂的风险. 我们都记得Java 7发行时有一系列非常严重的错误 . 当然,我们所有人都可以帮助避免在Java 8中 ...

  3. java 免登录_最简单、稳定的免密登录

    先说下环境:CentOS7 X64. 最近折腾本地Hadoop集群环境,在免密的登录的时候,再次遇到以前的问题,虽然最后解决,但总感觉抓不到关键点,必须找一个稳定可行且简单的方式. 正常而言,很多做免 ...

  4. 数据库性能优化步骤_五个简单步骤即可提高数据库性能

    数据库性能优化步骤 2015年1月30日:根据读者的反馈意见,第4节"您是否有足够的数据库连接?" 已修改. 数据库访问是大多数应用程序的核心功能. 根据我们的经验,对于我们看到的 ...

  5. 家用计算机历史记录,如何查看计算机使用历史记录,只需几个简单步骤即可查看...

    很多时候我们的计算机将被借给同事或朋友使用,而其他人将使用我们的计算机来保存操作记录,那么如何查看计算机的使用记录?今天,编辑器告诉您以一种简单的步骤查看计算机使用记录的方法. 有需要的朋友下次可以学 ...

  6. 登录linux系统进去的步骤,Linux系统的?登录和退出操作步骤

    关于 Linux系统的登录和退出操作步骤: 1.启动和登录系统 超级用户的用户名为root, 密码在安装系统时已设定,系统启动成功后屏幕显示下面的提 示: localhost login: 这时输入超 ...

  7. Android微信登录以及分享集成步骤

    准备工作 在应用集成微信登录以及分享之前,我们在微信开放平台必须要个开发者账户 1.注册完之后创建一个移动应用 2.填写对应应用包名以及签名(md5)信息,填写完毕后,会有个审核过程,一般第二天就通过 ...

  8. SSH无密码登录:只需两个简单步骤 (Linux)

    最后更新 2017年4月8日 分类 最新文章 服务器安全 标签 RSA SSH Key 非对称加密 如果你管理一台Linux服务器,那么你就会知道每次SSH登录时或者使用scp复制文件时都要输入密码是 ...

  9. linux 无密码登录另一台服务器,ECS Linux服务器ssh免密码登录另外一台服务器的具体设置...

    若有多台linux服务器,为方便起见,服务器之前可设置免密码ssh登录,具体操作参考如下所示: 1 .登录其中一个服务器,执行ssh-keygen -t rsa,按3次回车,将会生成公钥和私钥文件id ...

最新文章

  1. python3 _笨方法学Python_日记_DAY3
  2. js 文件不让通过地址访问_区块链与以太坊实战(5):访问以太坊节点的N中方式...
  3. 关于WinForm的博客推荐
  4. 新手探索NLP(二)
  5. 【设计模式】迭代器模式 ( 简介 | 适用场景 | 优缺点 | 代码示例 )
  6. centos08-Linux服务器上发布java项目
  7. display none的元素重新展示如何撑开页面_【第1962期】巧用 display: contents 增强页面语义...
  8. 华为怎么显示返回按键_华为 iateey 智能饮水吧评测:即时加热,一秒出水
  9. 为什么volatile不能保证原子性而Atomic可以?
  10. core文件与gdb调试
  11. Fletcher-Reevers Conjugate Descent和Steepest Descent两种算法中伪代码的区别
  12. 安装hive出现的各种问题(这些问题出现在spark连接mysql的时候)
  13. Cloud Native 介绍
  14. 厦门银行服务器没有收到证书,FRM证书申请成功后,一直未收到证书该如何做?...
  15. Grid Coloring(AtCoder-2687)
  16. Android Html.fromhtml
  17. 微软发布ASP.NET 5路线图
  18. List集合去重的几种方法
  19. 小米笔记本安装原生win7
  20. 数据中心行业深度报告:从财务分析看IDC行业的投资价值

热门文章

  1. My.WinformMvc,一个 Winform MVC 框架
  2. Java学习笔记-12.传递和返回对象
  3. LLVM每日谈之三 如何创建一个LLVM工程
  4. [转载] Python3 字典 values() 方法
  5. [转载] Numpy 使用教程--Numpy 数学函数及代数运算
  6. [转载] java 中 date类型详解
  7. 2019牛客多校 Round2
  8. AOP 面向切面编程、拦截器
  9. Vue.js 使用 Swiper.js 在 iOS 11 时出现错误
  10. 读过的设计模式的书小结