linux ssh-copy-id,SSH 免密码登录 ssh-copy-id 命令

如果你管理一台 Linux Server,那么你就会知道每次 SSH 登录时或者使用 scp 复制文件时都要输入密码是一个多么繁琐的过程,免密码登陆其实很简单。

SSH无密码登录的设置步骤:

1.本地 Linux 生成 SSH 密钥和 SSH 公钥

首先我们在自己的 Linux 系统上生成一对 SSH Key:SSH密钥和SSH公钥。密钥保存在自己的Linux系统上。

然后公钥上传到 Linux Server,之后我们就能无密码SSH登录了。

打开终端,使用下面的 ssh-keygen 来生成 RSA 密钥和公钥.-t表示type,就是说要生成RSA加密的钥匙.

ssh-keygen -t rsa

RSA也是默认的加密类型.所以你也可以只输入 ssh-keygen。默认的RSA长度是2048位,也可以指定 4096 位长度.

ssh-keygen -b 4096 -t rsa

生成 SSH Key 的过程中会要求你指定一个文件来保存密钥,按Enter键使用默认即可。然后需要输入一个密码来加密你的SSH Key。

SSH 密钥会保存在 home 目录下的.ssh/id_rsa 文件中。

SSH公钥保存在.ssh/id_rsa.pub文件中.

Generating public/private rsa key pair.

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

Enter passphrase (empty for no passphrase):   输入一个密码

Enter same passphrase again:   再次输入密码

Your identification has been saved in /home/matrix/.ssh/id_rsa.

Your public key has been saved in /home/matrix/.ssh/id_rsa.pub.

The key fingerprint is:

e1:dc:ab:ae:b6:19:b0:19:74:d5:fe:57:3f:32:b4:d0 matrix@vivid

The key's randomart image is:

+---[RSA 4096]----+

| .. |

| . . |

| . . .. . |

| . . o o.. E .|

| o S ..o ...|

| = ..+...|

| o . . .o .|

| .o . |

| .++o |

+-----------------+

2将 SSH 公钥上传到Linux服务器

可以使用ssh-copy-id命令来完成。

ssh-copy-id username@remote-server

SSH公钥会自动上传。

SSH公钥保存在远程Linux服务器的 .ssh/authorized_keys

大功告成

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值