Linux配置免密登录

1、公钥-私钥对:

称为非对称加密方式

2、生成公钥-私钥对命令:

  • 参数:
    -t:加密算法 rsa:不对称加密算法,2048位长度
    -C:标识身份,尽量不使用中文
    -f:输出密钥的文件名
> ssh-keygen -t rsa -C "Chumingze" -f "chumingze_ke

3、私钥生效

3.1、本地机器的将私钥放到.ssh文件夹内

> root/.ssh 路径

3.2、设置私钥文件权限

设置自己用户的访问权限

> chmod 600 "chumingze_key"

3.3、配置config文件

> cat config

参考格式:

单私钥

User root
Host yideng
HostName www.yideng.com
Port 22
StrictHostKeyChecking no
IdentityFile ~/.ssh/chumingze_key
IdentitiesOnly yes
Protocol 2
Compression yes
ServerAliveInterval 60
ServerAliveCountMax 20
LogLevel INFO

多私钥

Host gateway-produce
HostName 192.168.2 221
Port 22
Host node-produce
HostName 192.168.2.222
Port 22
Host java-produce
HostName 192.168.2.223
Port 22

Host *-produce
User root
IdentityFile ~/.ssh/produce_key
Protocol 2
Compression yes
ServerAliveInterval 60
ServerAliveCountMax 20
LogLevel INFO

3.4、配置known_hosts文件

保存目标服务器的免密指纹,第一次登录目标服务器时,会记录到known_hosts文件中

> ssh [email protected]

4、公钥生效

4.1、目标服务器的将公钥放到.ssh文件夹内

> root/.ssh 路径

4.2、创建并修改authorized_keys文件

> cat chumingze_key.pub >> authorized_keys
> chmod 644 "authorized_keys"

你可能感兴趣的:(Linux配置免密登录)