
SSH是一种网络协议,用于通过网络连接到其他计算机上的操作系统。它是一种常用的安全远程访问方式,使得用户可以在不同的计算机上无需亲自出席,完成一系列的任务。在Linux上使用SSH可以轻松地远程访问其他计算机,但是每次都要输入密码或者密钥对却是一件非常繁琐的事情。为了节省时间,在这里教大家如何在Linux上使用SSH无密码登录。
在Linux上使用SSH无密码登录需要做的步骤如下:
1. 生成密钥对
首先需要生成一个公钥和一个私钥。在终端中输入以下指令:
“`
ssh-keygen -t rsa
“`
这个命令会要求你输入密钥的存储路径和密码(可不填)。按Enter键之后就可以生成公钥和私钥。默认情况下,这个密钥对会被存储在~/.ssh目录下。
2. 将公钥复制到远程服务器
将刚刚生成的公钥复制到远程服务器上。在终端中输入以下指令:
“`
ssh-copy-id username@remote_host
“`
在这个命令中,username是远程服务器的用户名,remote_host是远程服务器的IP地址或者域名。你会被要求输入密码,输入正确密码后,公钥就会被复制到远程服务器的~/.ssh/authorized_keys文件中。
3. 测试SSH登录
接下来使用ssh命令来测试SSH登录是否成功。在终端中输入以下指令:
“`
ssh username@remote_host
“`
如果SSH配置成功,你将可以轻松地登录远程服务器,而无需输入密码。
SSH是一种非常有用的远程访问方式。使用SSH无密码登录可以使你节省大量的时间。希望这篇文章能够帮助你快速地在Linux上使用SSH无密码登录。
相关问题拓展阅读:
- linux下怎样设置ssh无密码登录
linux下怎样设置ssh无密码登录
第1步:在本地主机中生成“密钥对”并将公钥传送到远程服务器中:
# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):直接敲击回车或设置密钥的存储路径
Created directory ‘/root/.ssh’.
Enter passphrase (empty for no passphrase): 直接敲击回车或设置密钥的密码
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:
40:32:48:18:e4:ac:c0:c3:c1:ba:7c:6c:3a:a8:b5:22
The key’s randomart image is:
+——+
|+*..o .|
|*.o +|
|o* .|
|+ . .|
|o.. S|
|.. +|
|. =|
|E+ .|
|+.o|
+—+
第2步:将或腔生成好的私钥文件传送至远程主机:
# ssh-copy-id 192.168.10.20
The authenticity of host ‘192.168.10.20 (192.168.10.20)’ can’t be established.
ECDSA key fingerprint is 4f:a7:91:9e:8d:6f:b9:48:02:32:61:95:48:ed:1e:3f.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed — if you are prompted now it is to install the new keys
‘s password:此处输入远程服务器主机密码
Number of key(s) added: 1
Now try logging into the machine, with: “ssh ‘192.168.10.20’”
and check to make sure that only the key(s) you wanted were added.
第3步:设置服务器主机只允许密钥验证,拒绝传统口令验证方式,记得修改配置文件后保存并重启sshd服务程序哦~:
# vim /etc/ssh/sshd_config
…衫镇衫……………省略部分输出信息………………
75 # To disable tunneled clear text passwords, change to no here!
76 #PasswordAuthentication yes
77 #PermitEmptyPasswords no
78 PasswordAuthentication no
………………省略部分输出信息………………
# systemctl restart sshd
第4步:在客户端主机尝试登陆到服务端主机,此时无旅粗需输入密码口令也可直接验证登陆成功:
# ssh 192.168.10.20
Last login: Mon Apr 13 19:34:
ssh的话你可以详细看一下
关于linux ssh无密码登陆的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。
香港服务器首选树叶云,2H2G首月10元开通。
树叶云(www.IDC.Net)提供简单好用,价格厚道的香港/美国云服务器和独立服务器。IDC+ISP+ICP资质。ARIN和APNIC会员。成熟技术团队15年行业经验。
文章来源网络,作者:运维,如若转载,请注明出处:https://shuyeidc.com/wp/202431.html<