linux配置免密远程登录
配置ssh
安装 OpenSSH 服务端
$ sudo apt-get install openssh-server -y
手动启动并设置自启动
sudo service ssh start sudo systemctl enable ssh
有关命令
#查看SSH状态: sudo systemctl status ssh #关闭SSH服务开机自动启动: sudo systemctl disable ssh #手动启动SSH服务: sudo systemctl start ssh #手动停止SSH服务: sudo systemctl stop ssh
测试远程登陆:格式
ssh user@xxx.xxx.xxx.xxx
user是linux账户名,IP地址查询方式: ip addr
如果远程连接后更新过系统,会有这样的警告,此时需要重置下
ssh-keygen -R xxx.xxx.xxx.xxx
如果开启了防火墙,则需要将22端口加入白名单
sudo ufw allow 22 sudo ufw allow OpenSSH sudo ufw enable
生成公钥,参考https://blog.csdn.net/SXY16044314/article/details/90605069;
服务器将id_rsa.pub中的公钥粘贴在~/.ssh/authorized_keys下
# 生成目录 mkdir ~/.ssh/ # 进入编辑 sudo nano ~/.ssh/authorized_keys
保存,重新连接即可免密
出于安全考虑,许多 Linux 系统默认禁止 root 用户通过 SSH 直接登录。系统的 SSH 配置文件(/etc/ssh/sshd_config
)中可能设置了PermitRootLogin no.以具有 sudo 权限的普通用户登录远程系统,然后编辑
/etc/ssh/sshd_config
文件,将PermitRootLogin no
修改为PermitRootLogin yes
。修改完成后,保存文件并重启 SSH 服务。在 Ubuntu 和 Debian 系统中,可以使用sudo service ssh restart
命令;
终端使用代理
export https_proxy=http://127.0.0.1:7890;export http_proxy=http://127.0.0.1:7890