---
url: https://chenlj.top/md/develop/linux/sshkey.md
---
# 使用 ssh 公私钥对登陆服务器

## 1.查看本机是否已经生成过 SSh key

```shell
ls -al ~/.ssh
```

## 2.使用命令生成

```shell
ssh-keygen -t rsa -C "chenlj"
```

一路回车，即可生成公司要对

> SSH 秘钥的两个文件：
> id\_rsa —— SSH 秘钥的 私钥 (Private Key)
> id\_rsa.pub —— SSH 秘钥的 公钥 (Public Key)

## 3.复制文件

1.将 id\_rsa.pub 复制给 authorized\_keys

```shell
cp ~/.ssh/id_rsa.pub  ~/.ssh/authorized_keys
```

2.将 id\_rsa 复制到需要的地方

即可使用该私钥进行登陆
