linux密钥登录sftp,设置LinuxSSH通过密钥登录

一、制作密钥对

首先在服务器上制作密钥对。用密码登录到你打算使用密钥登录的账户,然后执行以下命令:

[root@host ~]$ ssh-keygen //建立密钥对 Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): //按Enter Created directory '/root/.ssh'. Enter passphrase (empty for no passphrase): //输入密钥锁码,或直接按 Enter 留空 Enter same passphrase again: //再输入一遍密钥锁码 Your identification has been saved in /root/.ssh/id_rsa //私钥 Your public key has been saved in /root/.ssh/id_rsa.pub //公钥 The key fingerprint is: 0f:d3:e7:1a:1c:bd:5c:03:f1:19:f1:22:df:9b:cc:08 root@host

密钥锁码在使用私钥时必须输入,这样就可以保护私钥不被盗用。当然,也可以留空,实现无密码登录。

现在,在 root 用户的家目录中生成了一个 .ssh 的隐藏目录,内含两个密钥文件。id_rsa 为私钥,id_rsa.pub 为公钥。

二、在服务器上安装公钥

- 使用ssh-copy-id安装:

```

#命令格式

ssh-copy-id -i 公钥文件 用户名@主机 -p 端口

```

如:`ssh-copy-

你可能感兴趣的:(linux密钥登录sftp)