Ubuntu设置远程连接免密码
时间: 2024-11-06 09:11:11 浏览: 89
在Ubuntu系统上设置远程连接免密码,通常需要通过SSH密钥对的方式来实现,这可以提供更安全的无密码登录体验。以下是步骤:
1. **生成SSH密钥对**:
打开终端,输入命令:
```
ssh-keygen -t rsa
```
按照提示操作,通常选择默认选项即可。
2. **查看公钥**:
查看生成的公钥:
```
cat ~/.ssh/id_rsa.pub
```
3. **将公钥添加到目标服务器的authorized_keys文件**:
登录到目标服务器并打开`~/.ssh/authorized_keys`文件(如果不存在,新建并追加内容),复制你刚刚得到的公钥粘贴进去。
4. **配置客户端**:
在你的本地机器(通常是Linux或macOS)的`~/.ssh/config`文件中,添加类似这样的配置:
```
Host your_server_name
User your_username
IdentityFile ~/.ssh/id_rsa
```
这样每次你只需键入`ssh your_server_name`就可以自动登录了。
5. **启用SSH无密码登录**:
确保在你的Ubuntu服务器上已经设置了`PermitRootLogin without-password`,可以在`/etc/ssh/sshd_config`文件中查找并修改这一行。
6. **重启SSH服务**:
```
sudo service ssh restart
```
完成以上步骤后,你应该就可以无密码地从本地电脑远程连接到Ubuntu服务器了。注意,尽管方便,但也增加了安全性风险,因此仅在信任的环境中使用。
阅读全文
相关推荐


















