linux 修改登录端口,免密登录

查看系统版本:

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 ~]#
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值