Linux下不使用密码远程登录

Par*_*_90 1 remote-access redhat-enterprise-linux

我是 Linux 操作系统的新手。我正在使用红帽 Linux。

谁能告诉我如何在不提供密码的情况下使用远程服务登录到远程机器?

Linux 中是否有任何命令,或者我必须为它编写“C”代码吗?

Mu *_*iao 8

您不必编写代码。

首先生成您的密钥对

ssh-keygen
Run Code Online (Sandbox Code Playgroud)

其次,使用 ssh-copy-id 分发您的公钥

ssh-copy-id username@remote-machine
Run Code Online (Sandbox Code Playgroud)

请注意,运行此命令时需要提供密码。之后,您无需密码即可登录远程机器。

以下是手册页中命令的一些解释:

ssh-keygen

 ssh-keygen generates, manages and converts authentication keys for
 ssh(1).  ssh-keygen can create RSA keys for use by SSH protocol version 1
 and DSA, ECDSA or RSA keys for use by SSH protocol version 2.  The type
 of key to be generated is specified with the -t option.  If invoked with-
 out any arguments, ssh-keygen will generate an RSA key for use in SSH
 protocol 2 connections.
Run Code Online (Sandbox Code Playgroud)

ssh-copy-id

 ssh-copy-id  is  a  script  that  uses  ssh  to  log into a remote machine
 and append the indicated identity file to that machine's
 ~/.ssh/authorized_keys file.
Run Code Online (Sandbox Code Playgroud)