學習筆記,CentOS 7.6 Telnet服務搭建


 

正文:

Setup 1 系統信息 安裝

貼下系統信息  [圖1]

[root@azeroth ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)

 下面是已經安裝完成的Telnet版本查詢,如果還沒有安裝的是沒有包信息顯示的。[圖2]

[root@azeroth ~]# rpm -qa|grep telnet
telnet-server-0.17-64.el7.x86_64
telnet-0.17-64.el7.x86_64
[root@azeroth ~]# rpm -qa|grep xinetd
xinetd-2.3.15-13.el7.x86_64

 Telnet 遠程登陸工具,Windows里面常常用來測試端口用(- .- !),Xinetd 第一次看見,百科里說是監視網絡需求的守護進程(不曉得除了telnet以外還有什么網絡服務會用這個?求教) ,等下有個叫telnet的配置文件要寫在這里面。

安裝

果斷YUM哇!(呵呵,沒有網?ISO,光驅這兩樣總得有一樣吧,手工掛載制作CentOS-Media.repo源)[圖3]

[root@azeroth ~]# yum install telnet telnet-server xinetd -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * c7-media:
......

 執行完就可以查看到 [圖2] 的結果了 。

Setup 2 Telnet進程配置

配置 (重點來了)

  安裝完以上會在 /etc/xinetd.d/ 目錄下生成很多配置文件,ls 看是否有一個名為 telnet 的配置文件,嘗試過兩台設備 一台安裝完會出現 telnet的默認配置,一台則沒有,具體原因不詳,暫時沒查明原因,不過這個不重要可以參看 百科 xinetd制作一個,也可以copy一個。[圖 4]

 [root@azeroth ~]# ll /etc/xinetd.d/telnet
-rw-r--r--. 1 root root 342 Oct 21 21:21 /etc/xinetd.d/telnet
[root@azeroth ~]# cat /etc/xinetd.d/telnet
# default: on
# # description: The telnet server serves telnet sessions; it uses \
# #   unencrypted username/password pairs for authentication.
# service telnet
# {
# disable = yes
# flags       = REUSE
# socket_type = stream
# wait        = no
# user        = root
# server      = /usr/sbin/in.telnetd
# log_on_failure  += USERID
# }

配置解釋(解釋不對的地方,請大神指點):

存在此配置文件的情況下, 無需修改,是可以正常使用普通用戶登陸Telnet服務器的親測。

說明部分:默認情況下telnet服務為開啟, telnet 服務器為 telnet 會話提供服務(廢話),它使用未加密的用戶名/密碼對進行身份驗證(試了一下創建一個沒有分配密碼的用戶也沒登陸上去)。

{ }部分

# disable = yes           //我理解的意思大概是說 { } 內的字段默認情況下是不被使用的(這個理解似乎有問題,原文:”用在默認的 {} 中 禁止服務“,希望有大神指引一下)

# flags    = REUSE         //沒有理解這里的意思是什么,請大神幫忙解答 “標識 = 可重復使用” ?

# socket_type = stream       // 網絡套接字類型

# user        = root            //使用root用戶運行服務

# server      = /usr/sbin/in.telnetd   //執行進程路徑

# log_on_failure  += USERID    //登陸失敗日志

  注:# disable = yes 此字段為 yes 或者 no 都不是決定能否使用root登陸的條件(此處被度娘搜索到的帖子誤導了) 

   其實,Setup3 說了這么多,做了很多次實驗和測試,此配置文件和是否能使用root登陸Telnet並沒有直接的關系(決定是否能使用root登陸和另外一個配置有關系下文 敘述Setup 6,此配置文件理解的更多的是和Telnet的服務進程有關,哪么問題來了,此配置文件有存在的意義嗎?當然,Xinet是用來監視守護網絡進程的,Telnet是被Xinetd監視守護的對象,類似於監聽的意思,但是比監聽功能更強,如上的配置就是用作如何監視,用什么權限監視的配置。

Setup3 可以啟動了

  完成上面的安裝和Xinetd配置檢查,接下來就該添加自啟動和運行服務了 [圖 5 圖 6 ]

[root@azeroth ~]# systemctl enable xinetd.service
[root@azeroth ~]# systemctl start xinetd.service
[root@azeroth ~]# systemctl status xinetd.service
● xinetd.service - Xinetd A Powerful Replacement For Inetd
   Loaded: loaded (/usr/lib/systemd/system/xinetd.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2019-10-22 22:07:22 CST; 4min 29s ago
 Main PID: 6883 (xinetd)
   CGroup: /system.slice/xinetd.service
           └─6883 /usr/sbin/xinetd -stayalive -pidfile /var/run/xinetd.pid

Oct 22 22:07:22 azeroth systemd[1]: Started Xinetd A Powerful Replacement For Inetd.
Oct 22 22:07:22 azeroth xinetd[6883]: removing discard
Oct 22 22:07:22 azeroth xinetd[6883]: removing discard
Oct 22 22:07:22 azeroth xinetd[6883]: removing echo
Oct 22 22:07:22 azeroth xinetd[6883]: removing echo
Oct 22 22:07:22 azeroth xinetd[6883]: removing tcpmux
Oct 22 22:07:22 azeroth xinetd[6883]: removing time
Oct 22 22:07:22 azeroth xinetd[6883]: removing time
Oct 22 22:07:22 azeroth xinetd[6883]: xinetd Version 2.3.15 started with libwrap loadavg labeled-networking options compiled in.
Oct 22 22:07:22 azeroth xinetd[6883]: Started working: 0 available services

  

[root@azeroth ~]# systemctl enable telnet.socket
[root@azeroth ~]# systemctl start telnet.socket
[root@azeroth ~]# systemctl status telnet.socket
● telnet.socket - Telnet Server Activation Socket
   Loaded: loaded (/usr/lib/systemd/system/telnet.socket; enabled; vendor preset: disabled)
   Active: active (listening) since Tue 2019-10-22 22:07:06 CST; 6min ago
     Docs: man:telnetd(8)
   Listen: [::]:23 (Stream)
 Accepted: 1; Connected: 0

Oct 22 22:07:06 azeroth systemd[1]: Listening on Telnet Server Activation Socket.

Setup 4  防火牆放行

  最容易感覺到的卻也是最容易被遺忘的,搗鼓了半天咋還不能登陸,防火牆忘記放行啦!什么 Selinux還沒關閉呢?(很多配置Telnet的帖子都提到需要關閉Selinux,不知道是何用意)不存在的,Firewall 放行了還需要關閉Selinux嘛?,親測是不需要關閉的,Selinux安全上下文畢竟是Redhat系列系統的安全防護重點,不論配置什么應用建議都不要隨意關閉,畢竟安全問題不能忽略。[圖 7 ]

[root@azeroth ~]# firewall-cmd --add-port=23/tcp --permanent
success
[root@azeroth ~]# firewall-cmd --reload
success

Setup 5 完成

      完成以上步驟,基本實現了Telnet服務的搭建,快到CMD里面使用Telnet 連接一下試試看吧!請使用普通用戶,root權限還沒開 ,如果不行請按照步驟檢查或reboot。[圖 8]

[root@azeroth ~]# telnet 192.168.11.130
Trying 192.168.11.130...
Connected to 192.168.11.130.
Escape character is '^]'.

Kernel 3.10.0-957.5.1.el7.x86_64 on an x86_64
azeroth login: zym
Password:
Last login: Tue Oct 22 20:09:08 from ::ffff:192.168.11.1
[zym@azeroth ~]$

Setup 6 Root權限登陸配置 

  (不建議開啟root權限,以上使用普通用戶登陸之后即可su切換root了,一省事,二安全,兩全其美)如果需要使用root權限登陸Telnet,還需要配置 /etc/securetty,將root允許使用telnet登陸的pts字段添加進配置文件。[圖 9 圖10] 

[root@azeroth ~]# echo 'pts/0' >>/etc/securetty
[root@azeroth ~]# echo 'pts/1' >>/etc/securetty
[root@azeroth ~]# tail -f /etc/securetty
hvc4
hvc5
hvc6
hvc7
hvsi0
hvsi1
hvsi2
xvc0
pts/0
pts/1
[root@azeroth ~]# systemctl restart telnet.socket

  以上關於CentOS7.6 系統Telnet服務的配置就全部介紹完了。感謝!

  第一次發表隨筆博文有點捉襟見肘

                                   

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM