【原创】Linux基础之SSH秘钥登录

密钥类型包括rsa和dsa,详见 https://security.stackexchange.com/questions/5096/rsa-vs-dsa-for-ssh-authentication-keys

The security of the RSA algorithm is based on the fact that factorization of large integers is known to be "difficult", whereas DSA security is based on the discrete logarithm problem.

rsa基于大数分解,dsa基于离散对数;

RSA keys can go up to 4096 bits, where DSA has to be exactly 1024 bits (although OpenSSL allows for more.)

rsa key最高支持4096长度bit,dsa key只支持1024长度bit;

1 生成秘钥,rsa或者dsa

1.1 命令生成(linux或mac)

$ ssh-keygen -t rsa -b 4096
Generating public/private rsa key pair.
Enter file in which to save the key (/home/testuser/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/testuser/.ssh/id_rsa.
Your public key has been saved in /home/testuser/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:mRMuErgh17o9EPe1gzdd/tFuj6L0rVsk7qTw1rrGFCc testuser@testserver
The key's randomart image is:
+---[RSA 4096]----+
| |
| o |
|. = + o . |
| o * o + *Eo. . |
| + . + S .+o o .|
| + . o +.. + o |
| . o .o..o o o|
| . ++=oo o.|
| o*+=+o .|
+----[SHA256]-----+

创建过程会输入密码;

创建完成后默认会在home目录的.ssh目录下创建两个秘钥文件,公钥(pub后缀)和私钥

$ ls .ssh
id_rsa id_rsa.pub

 登录时私钥自己保存,公钥放到服务器上

1.2 securecrt或xshell界面生成(windows)

securecrt创建秘钥的地方在

Tools--Create Public Keys

2 上传公钥

将公钥上传到要登录的服务器的用户home目录下,同时将公钥加入authorized_keys

cat .ssh/id_rsa.pub >> .ssh/authorized_keys
chmod 600 .ssh/authorized_keys

3 本机私钥登录

3.1 ssh命令登录(linux或mac)

$ ssh -i /path/id_rsa user@remote_ip

3.2 securecrt或xshell登录(windows)

 选择私钥

猜你喜欢

转载自www.cnblogs.com/barneywill/p/10271679.html