ssh登录配置

生成密钥对的途径

方式一

通过客户端软件生成密钥对,将公钥拷贝到远程主机的需要登录的用户目录的.ssh目录中
过程略

方式二

在远程主机中生成密钥对

  1. 生成密钥对
## 建立密钥对
ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): <== 按 Enter
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): <== 输入密钥锁码,或直接按 Enter 留空
Enter same passphrase again: <== 再输入一遍密钥锁码
Your identification has been saved in /root/.ssh/id_rsa. <== 私钥
Your public key has been saved in /root/.ssh/id_rsa.pub. <== 公钥
The key fingerprint is:
0f:d3:e7:1a:1c:bd:5c:03:f1:19:f1:22:df:9b:cc:08 root@host
  1. 将私钥拷贝到本地

修改ssh登录配置

  1. 在远程主机上配置公钥
[root@host ~]$ cd .ssh
[root@host .ssh]$ cat id_rsa.pub >> authorized_keys
  1. 修改密钥文件的权限
[root@host .ssh]$ chmod 600 authorized_keys
[root@host .ssh]$ chmod 700 ~/.ssh
  1. 修改sshd配置文件–需要root权限
vi /etc/ssh/sshd_config
—————————————————————————
## 开启sshd密钥登录
## 添加信息
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys # 指定公钥文件
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
## 禁用密码登录(最好是在重启sshd服务之后验证密钥登录成功之后再禁用)
## 修改信息,将yes改为no 
PasswordAuthentication no 
—————————————————————————
  1. 重启sshd服务
service sshd restart
or
systemctl restart sshd
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值