Linux 如何配置密钥登录以及长时间不自动退出
本人centos7.4 ubuuntu 类似
密钥登录
1.执行下面命令 一直回车就好了
$ ssh-keygen -t rsa -b 4096
2.生成秘钥后,编辑登录配置文件
vi /etc/ssh/sshd_config
.
.
PasswordAuthentication no //密码将不能登录
RSAAuthentication yes //私匙登录
PubkeyAuthentication yes
.
.
3.将/root/.ssh/id_rsa 拷贝到自己的电脑,然后使用git bash 或者xshell既可登入
ssh root@your ip address -i ~/.ssh/lamp_id_rsa
- 如果不能登录 可能还需要
cd ~/.ssh
cat id_rsa.pub >> authorized_keys
service sshd restart
ssh链接长时间自动退出问题
1.进入ssh服务目录
cd /etc/ssh
2.备份 sshd_config 文件
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
3 编辑sshd_config
vim /etc/ssh/sshd_config
找到 #ClientAliveInterval 0
改为 ClientAliveInterval 60
找到 #ClientAliveCountMax 3
改为 ClientAliveCountMax 3
4.重启sshd服务,使配置生效
sudo systemctl restart sshd
5.修改$TMOUT 系统环境变量
用以下命令判断是否是否设置了该参数,如果不为0则代表超时。
echo $TMOUT
修改TMOUT的值为0,不超时。
vim /etc/profile //最后加上
export TMOUT=0
使配置生效
source /etc/profile
个人博客停止维护,部分博客转载到这
- 彼特城
- 2020-10-22 15:04:17
本作品采用《CC 协议》,转载必须注明作者和本文链接