目录
查看系统版本:
cat /etc/redhat-release
本地显示:
服务器显示:
Red Hat Enterprise Linux Server release 6.9 (Santiago)
一、修改ssh端口
添加ssh端口
vi /etc/ssh/sshd_config,去掉默认Port 22前面的#,添加Port 33
保存退出,重启ssh服务 systemctl restart sshd
服务器提示 -bash: systemctl : command not found,使用/etc/rc.d/init.d/sshd restart重启
查看防火墙状态
systemctl status firewalld
active(running)则为开启,inactive (dead)则为关闭
服务器查看防火墙状态:service iptables status
如果开启显示:表格:filter…… 可以使用service iptables stop关闭防火墙,如果关闭显示 iptables:未运行防火墙
如果防火墙开启需要 服务器需要修改 /etc/rc.d/init.d/iptables添加33端口
--dport 22:33
使用/etc/rc.d/init.d/iptables restart重启防火墙
二、免密码登录
在A机下生成公钥/私钥对
[root@A ~]# ssh-keygen -t rsa -P ''
-P表示密码,-P '' 就表示空密码
把A机下的id_rsa.pub复制到B机.ssh/authorzied_keys文件里
scp -P(大写) 端口
[root@A ~]# scp -P 33 .ssh/id_rsa.pub root@100.16.34.163:/root/id_rsa.pub
[root@B ~]# cat id_rsa.pub >> .ssh/authorized_keys
同理B机生成密匙,id_rsa.pub复制到A机.ssh/authorzied_keys
A机登录B机
ssh -p(小写) 端口
[root@A ~]# ssh -p 33 100.16.34.163
The authenticity of host '100.16.34.163 (100.16.34.163)' can't be established.
RSA key fingerprint is 00:a6:a8:87:eb:c7:40:10:39:cc:a0:eb:50:d9:6a:5b.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.181' (RSA) to the list of known hosts.
Last login: Fri Feb 15 09:53:18 2019 from 100.33.32.139
[root@B ~]#