2.3.2 linux软件管理 : debian和RedHat体系常用软件安装 :openssh 安装

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/one_chao/article/details/89116623

2.3.2 linux软件管理 : debian和RedHat体系常用软件安装 :openssh 安装

  1. 安装
    debian体系
$sudo apt-get install openssh-server ##安装ssh服务端
$sudo /etc/init.d/ssh restart ##重启ssh

RedHat体系

$yum  install -y openssh-server openssh-clients ##安装ssh服务端
$service sshd start  ##启动ssh
  1. 生成key
ssh-keygen  ##会生成id_rsa  id_rsa.pub
  1. SSH远程登录
ssh 用户名@IP地址 -p 端口号
例如:[email protected] -p 22
  1. SSH 免密登陆
1、登录A机器 
2、ssh-keygen -t [rsa|dsa],将会生成密钥文件和私钥文件 id_rsa,id_rsa.pub或id_dsa,id_dsa.pub
3、将 .pub 文件复制到B机器的 .ssh 目录, 并 cat id_dsa.pub >> ~/.ssh/authorized_keys【好像必须这么做,复制不可以】
4、大功告成,从A机器登录B机器的目标账户,不再需要密码了;(直接运行 #ssh 192.168.20.60 )
【一句话 - 总结 - 总之就是把.pub复制到服务器的authorized_keys里面】
  1. SSH经常断开
$ vim /etc/ssh/sshd_config
找到下面两行
#ClientAliveInterval 0
#ClientAliveCountMax 3
去掉注释,改成
ClientAliveInterval 30    ##客户端每隔多少秒向服务发送一个心跳数据
ClientAliveCountMax 86400 ##客户端多少秒没有相应,服务器自动断掉连接
  1. 设置允许root登录
# vi /etc/ssh/sshd_config
注释掉 #PermitRootLogin without-password,添加 PermitRootLogin yes
# Authentication:
LoginGraceTime 120
#PermitRootLogin without-password
PermitRootLogin yes
StrictModes yes
重启 ssh  服务

猜你喜欢

转载自blog.csdn.net/one_chao/article/details/89116623