ssh密钥登录 linux_如何使用基于密钥的身份验证通过SSH通过无密码登录Linux?

ssh密钥登录 linux

ssh密钥登录 linux

Ssh provides secure remote connections to the remote systems. It is defacto protocol used to manage Linux and networking systems remotely via command line. Ssh provides a lot of extra features which makes it useful for different purposes. For example we can copy files to remote and local system via ssh with a secure manner. In order to make things straightforward we can use passwordless key based authentication for ssh protocol.

Ssh提供到远程系统的安全远程连接。 它是事实上的协议,用于通过命令行远程管理Linux和网络系统。 Ssh提供了许多额外的功能,使其可用于不同目的。 例如,我们可以通过ssh以安全的方式将文件复制到远程和本地系统。 为了使事情变得简单,我们可以对ssh协议使用基于无密码密钥的身份验证。

为客户端列出本地系统上的公钥和私钥 (List Public and Private Keys On Local system For Client)

In some cases there may exist public and private keys all ready. The default location for ssh user public and private keys is /home/user/.ssh  . So we will list whether the directory and keys exist. We will use  ls  command for this.

在某些情况下,可能存在准备好的公用密钥和专用密钥。 ssh用户公钥和私钥的默认位置是/home/user/.ssh 。 因此,我们将列出目录和密钥是否存在。 我们将使用ls命令。

$ ls -l /home/ismail/.ssh/
List Public and Private Keys On Local system For Client
List Public and Private Keys On Local system For Client
为客户端列出本地系统上的公钥和私钥

As we can see there is no ssh public or private key in this example.

如我们所见,此示例中没有ssh公钥或私钥。

在客户端上创建公钥和私钥 (Create Public and Private Keys On Client)

The first step is creating public and private key pairs on the client system.Public key is copied to the remote system and private key is hold on the local system. Private key should be only known by the local system user. We will use ssh-keygen  command. This command will create keys named id_rsa.pub  and id_rsa .

第一步是在客户端系统上创建公钥和私钥对。将公钥复制到远程系统,并将私钥保留在本地系统上。 私钥应仅由本地系统用户知道。 我们将使用ssh-keygen命令。 该命令将创建名为id_rsa.pubid_rsa密钥。

$ ssh-keygen
Create Public and Private Keys On Client
Create Public and Private Keys On Client
在客户端上创建公钥和私钥

使用ssh-copy-id将公用密钥复制到服务器(Copy Public Key to the Server with ssh-copy-id)

We will use ssh-copy-id  command in order to copy ssh public key to the remote system. We will provide the remote system IP address and if the remote user is different from local user the username. In this example we use current user.

我们将使用ssh-copy-id命令将ssh公钥复制到远程系统。 我们将提供远程系统IP地址,如果远程用户与本地用户不同,则提供用户名。 在此示例中,我们使用当前用户。

$ ssh-copy-id 192.168.43.129
Copy Public Key to the Server with ssh-copy-id
Copy Public Key to the Server with ssh-copy-id
使用ssh-copy-id将公用密钥复制到服务器

As we can see from output 1 key is added to the remote system.

从输出1中可以看到,密钥已添加到远程系统。

LEARN MORE  NoMachine - Download, Install and Use For NX, SSH Connections
了解更多NoMachine-下载,安装和用于NX,SSH连接

使用ssh echo将公钥复制到服务器(Copy Public Key to the Server with ssh echo)

We have alternative way to copy key to the remote other than ssh-copy-id . As stated previously ssh  provides different features which makes system administrators life easy. We can run commands on remote system without an interactive shell. We will use this feature with echo  command where our key will be copied to the remote system.

除了ssh-copy-id之外,我们还有其他方法可以将密钥复制到远程计算机。 如前所述, ssh提供了不同的功能,使系统管理员的工作变得轻松。 我们可以在没有交互式shell的远程系统上运行命令。 我们将在echo命令中使用此功能,其中我们的密钥将被复制到远程系统。

$ cat .ssh/id_rsa.pub | ssh 192.168.43.129  'cat >> .ssh/authorized_keys'

使用无密码连接 (Connect with Passwordless)

Now we have completed all steps. We can simply connect remote system passwordless with ssh just running following command.

现在我们已经完成了所有步骤。 我们只需运行以下命令就可以使用ssh简单地连接无密码的远程系统。

$ ssh 192.168.43.129
Connect with Passwordless
Connect with Passwordless
使用无密码连接

翻译自: https://www.poftut.com/how-to-login-to-linux-with-passwordless-via-ssh-with-key-based-authentication/

ssh密钥登录 linux

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值