Linux ssh generates public and private keys and private keys to log in to ssh without password

Log in to Linux using asymmetric keys
1. Use ssh-keygen to generate public and private keys and press Enter all the way

2. The ~/.ssh/authorized_keys file on the server (Linux) side stores the public key to ensure that the SSH service is turned on. The default port is 22.

3. Save the private key yourself and use the ssh command when logging in.

# 生成密钥
ssh-keygen -t rsa -b 4096 -f ~/data/key/id_test_rsa -C "[email protected]"

-t 密钥类型, dsa | ecdsa | ed25519 | rsa
-b RSA类型密钥的大小(长度),通常至少应该是 2048,默认 3096
-f 指定私钥的文件名,e.g. ~/.ssh/private_key_name
-C 指定一个注释

#~/data/key下会生成两个文件,私钥:id_test_rsa,公钥:id_test_rsa.pub

# 将公钥放到 ~/.ssh/authorized_keys 文件中
cat id_rsa.pub >> authorized_keys

# 私钥登录
ssh user@host/ip[:port] -i [identity_file]

e.g. [email protected] -i ~/.ssh/id_rsa

-i identity_file 指定私钥文件

#如果提示缺权限,给私钥600权限
chmod 600 id_rsa


Guess you like

Origin blog.csdn.net/asd54090/article/details/131788721
Recommended