当前位置:首页 » 操作系统 » linuxrsa

linuxrsa

发布时间: 2025-01-07 03:25:04

linux怎么用秘钥登录

1. 制作密钥对
在服务器上制作密钥对。首先用密码登录到你打算使用密钥登录的账户,然后执行以下命令:
[root@host ~]$ ssh-keygen <== 下面是相应的操作提示,以及密钥生成的位置都会告诉我们。
Generating public/private rsa key pair.Enter file in which to save the key (/root/.ssh/id_rsa): <== 按 EnterCreated 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

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

2. 在服务器上安装公钥
键入以下命令,在服务器上安装公钥:
[root@host ~]$ cd .ssh
[root@host .ssh]$ cat id_rsa.pub >> authorized_keys

如此便完成了公钥的安装。为了确保连接成功,请保证以下文件权限正确:
[root@host .ssh]$ chmod 600 authorized_keys[root@host .ssh]$ chmod 700 ~/.ssh

3. 设置 SSH,打开密钥登录功能
编辑 /etc/ssh/sshd_config 文件,添加如下设置:

sudo vi /etc/ssh/sshd_config
RSAAuthentication yesPubkeyAuthentication yes

接着保存后 另外,请留意 root 用户能否通过 SSH 登录:PermitRootLogin yes

当你完成全部设置,并以密钥方式登录成功后,再禁用密码登录:
PasswordAuthentication no

最后,重启 SSH 服务:
[root@host .ssh]$ service sshd restart

热点内容
app什么情况下找不到服务器 发布:2025-05-12 15:46:25 浏览:714
php跳过if 发布:2025-05-12 15:34:29 浏览:467
不定时算法 发布:2025-05-12 15:30:16 浏览:131
c语言延时1ms程序 发布:2025-05-12 15:01:30 浏览:166
动物园灵长类动物配置什么植物 发布:2025-05-12 14:49:59 浏览:735
wifi密码设置什么好 发布:2025-05-12 14:49:17 浏览:148
三位数乘两位数速算法 发布:2025-05-12 13:05:48 浏览:397
暴风影音缓存在哪里 发布:2025-05-12 12:42:03 浏览:542
access数据库exe 发布:2025-05-12 12:39:04 浏览:630
五开的配置是什么 发布:2025-05-12 12:36:37 浏览:365