设置linux服务器免密登录其实是比使用密码登录更安全的一种登录方式。
设置的方法很简单,主要按照一下三个步骤:
plaintext# 进入sshd的配置文件 [root@wucc-server ~]# vim /etc/ssh/sshd_config # 设置PubkeyAuthentication 开启 PubkeyAuthentication yes # 如果不需要密码登录可以将PasswordAuthentication设置为no PasswordAuthentication no #保存退出,重启sshd [root@wucc-server ~]# systemctl restart sshd
plaintext# 到客户端生产ssh-keygen [wucc@wucc ~]$ ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/home/wucc/.ssh/id_rsa): /home/wucc/.ssh/id_rsa already exists. Overwrite (y/n)? y Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/wucc/.ssh/id_rsa Your public key has been saved in /home/wucc/.ssh/id_rsa.pub The key fingerprint is: SHA256:toCiwmxNGftXYK5ZwzkjhdsOrVUHxlAPoLL4ekp+JYE wucc@wucc The key's randomart image is: +---[RSA 3072]----+ | o== | | o ..+ | | .o o + . o | | E..*.O + . | | ..=o+.%S. | |o.+o..Xo=. | |o= oo= o. | |= .o . | | ++ | +----[SHA256]-----+ # 上边表示在/home/wucc/.ssh/生成了id_rsa私钥和id_rsa.pub公钥。
plaintext# 使用ssh-copy-id [用户]@[服务器]可以将客户端的公钥上传到服务器 [wucc@wucc ~]$ ssh-copy-id root@server # 输入完服务器root的密码后,就可以免密登录了 [wucc@wucc ~]$ ssh root@server Last login: Tue May 16 19:51:48 2023 Welcome to Alibaba Cloud Elastic Compute Service ! [root@wucc-server ~]#
本文作者:wucc
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 BY-SA 许可协议。转载请注明出处!