redhat 7.6 ssh 服务配置

安装ssh 

yum install openssh

查看端口

netstat -ntpl

netstat -ntpl | grep :22

启动和关闭

service sshd restart/start/top     redhat6版本命令

systemctl restart/start/stop sshd.service    redhat7版本命令

随机启动

systemctl enable/disable sshd.service

ssh配置文件

/etc/ssh/sshd_config

PermitRootLogin yes/no   是否禁止root远程登录

ssh密码连接命令方式

ssh user@192.168.1.1 -p 22   监听端口号如果修改,需要 -p 加上端口连接

更改端口未能连接成功,查看防火墙是否关闭

ssh无密码连接方式

第一种方式:

客户端配置命令:

ssh-keygen -t rsa     //-t 代表rsa加密方式,不加-t默认用rss加密方式        //生成公钥和私钥(生成成功后,会在/root/.ssh/目录下,产生两个文件id_rsa id_rsa.pub)

scp  /root//.ssh/id_rsa.pub  root@192.168.1.1:/home/      (服务端IP:192.168.1.1 ,把公钥cp到服务端的home目录下)

服务端配置命令:

touch /root/.ssh/authorized_keys    这个文件不存在的话,先创建(存在不需要创建)

cat /home/id_rsa.pub >> /root/.ssh/authorized_keys

以上配置成功,测试是否需要密码验证

未能成功,检查ssh配置文件

PubkeyAuthentication  yes/no 

第二种方式:

客户端配置命令:

ssh-kengen    生成公钥和密钥

ssh-copy-id /root/.ssh/id_rsa.pub 192.168.1.1     (服务端IP:192.168.1.1 ,把公钥cp到服务端的/root/.ssh/目录下)

ssh root@192.168.1.1   测试连接是否需要密码验证

原文地址:https://www.cnblogs.com/MOMING95/p/11479383.html