访问非默认端口、图形转发

    xiaoxiao2025-05-18  46

    问题 修改主机B的sshd服务端口将端口号改为 8022重启 sshd 服务,确认监听状态从主机A远程登入主机B恢复主机B的sshd服务端口从主机A再次远程登入主机B,且支持图形程序 方案

    对于ssh服务,它有两个配置文件一个是/etc/ssh/sshd_config服务端配置文件,另一个是/etc/ssh/ssh_config客户端配置文件,经常用到是/etc/ssh/sshd_config服务端配置文件。

    步骤

    实现此案例需要按照如下步骤进行。

    步骤一:修改主机B的sshd服务端口

    在B上操作,将端口号改为 8022,命令操作如下所示:

    [root@pc15 桌面]# vim /etc/ssh/sshd_config        //注意配置文件为服务器端配置文件

    [root@pc15 桌面]# grep 8022 /etc/ssh/sshd_config  //注意此字段原先是被注释的

    Port 8022                                             //打开注释更改

    [root@pc15 桌面]#

    在B上操作,重启 sshd 服务,确认监听状态,命令操作如下所示:

    [root@pc15 桌面]# netstat -anptu | grep 8022

    [root@pc15 桌面]# /etc/init.d/sshd restart           //需重启服务才能神效

    停止 sshd:                                                [确定]

    正在启动 sshd:                                            [确定]

    [root@pc15 桌面]# netstat -anptu | grep 8022

    tcp        0      0 0.0.0.0:8022      0.0.0.0:*                LISTEN      3052/sshd           

    tcp        0      0 :::8022                     :::*            LISTEN      3052/sshd           

    [root@pc15 桌面]#

    步骤二:从主机A远程登入主机B

    在A上操作,命令操作如下所示:

    [root@svr5 ~]# ssh root@192.168.8.15 

    ssh: connect to host 192.168.8.15 port 22: Connection refused

    [root@svr5 ~]# ssh -p 8022 root@192.168.8.15     //需加上-p选项和对应的端口号    

    root@192.168.8.15's password:

    Last login: Tue Mar  3 10:43:50 2015 from svr5.tarena.com

    [root@pc15 ~]#                           //访问成功

    恢复主机B的sshd服务端口,在B上操作,命令操作如下所示:

    [root@pc15 桌面]# vim /etc/ssh/sshd_config

    [root@pc15 桌面]# grep 8022 /etc/ssh/sshd_config    //将其注释即可,遵循默认端口22

    #Port 8022

    [root@pc15 桌面]# /etc/init.d/sshd restart

    停止 sshd:                                                [确定]

    正在启动 sshd:                                            [确定]

    [root@pc15 桌面]# netstat -anptu | grep 22

    tcp        0      0 0.0.0.0:22    0.0.0.0:*                   LISTEN      3139/sshd           

    tcp        0      0 :::22          :::*                        LISTEN      3139/sshd           

    [root@pc15 桌面]#

    从主机A再次远程登入主机B,且支持图形程序,在A上操作,命令操作如下所示:

    [root@svr5 桌面]# ssh -X root@192.168.8.15         //加上-X选项

    root@192.168.8.15's password:

    Last login: Tue Mar  3 11:25:59 2015 from svr5.tarena.com

    /usr/bin/xauth:  creating new authority file /root/.Xauthority

    [root@pc15 ~]# firefox

    最新回复(0)