Linux ssh无密登陆
Posted 周天祥
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux ssh无密登陆相关的知识,希望对你有一定的参考价值。
Linux ssh无密登陆
1、生成SSH密钥和公钥
执行命令后,一直回车
ssh-keygen -t rsa
[lucky@gitlab ~]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/lucky/.ssh/id_rsa):
Created directory '/home/lucky/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/lucky/.ssh/id_rsa.
Your public key has been saved in /home/lucky/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:b5kgwZQZAEakL1d7HCx7kLUwhau00dS9SLaNFlk+RJU lucky@gitlab
The key's randomart image is:
+---[RSA 2048]----+
| o=.+==O+... |
| o oOO+. E |
|. o=+**o. |
| .o.o*=oo. |
|..o+o.= S |
| oo o . o o |
| = |
| . |
| |
+----[SHA256]-----+
2、新建一个authorized_keys的文件,用来存放生成的密钥以及其它机器或用户的密钥
cat id_rsa.pub >> authorized_keys
3、查看权限 authorized_keys
ll ~/.ssh
确保authorized_keys的权限是600
如果不是则修改
chmod 600 authorized_keys
4、如果多机器或用户使用同意对秘钥,可以复制,但一定要保证权限
.ssh目录权限是700,
authorized_keys的权限是600
mkdir ~/.ssh
chmod 700 ~/.ssh
scp /home/lucky/.ssh/* ~/.shh/
chmod 600 ~/.shh/authorized_keys
以上是关于Linux ssh无密登陆的主要内容,如果未能解决你的问题,请参考以下文章