歡迎您光臨本站 註冊首頁

LINUX-TELNET/SSH配置

←手機掃碼閱讀     火星人 @ 2014-03-09 , reply:0

TELNET/SSH服務的配置.

TELNET簡介:

telnet,最早是用於連接BBS的工具.它在網路中傳輸數據時使用的是明文方式,這帶來了安全隱患,由於它是以明文方式傳輸,漸漸被ssh代替.ssh就是在telnet基礎上增加了安全性的遠程登錄軟體,ssh在網路中傳輸的數據是經過加密的.

TELNET基本配置:

安裝軟體:

[root@rhel ~]# rpm -ivh /misc/cd/Server/telnet-server-0.17-39.el5.i386.rpm

啟動telnet

最簡單的方法是使用ntsysv命令調出圖形界面把telnet選擇即可.

[root@rhel ~]# ntsysv

第二種方法:編輯配置文件:

[root@rhel ~]# vi /etc/xinetd.d/telnet

service telnet

{

flags = REUSE

socket_type = stream

wait = no

user = root

server = /usr/sbin/in.telnetd

log_on_failure = USERID

disable = no //只需修改這裡即可.

}

[root@rhel ~]# service xinetd restart //telnetxinetd的一個子服務.

測試:(關掉伺服器的防火牆)

C:\>telnet 192.168.10.10

Red Hat Enterprise Linux Server release 5.3 (Tikanga)

Kernel 2.6.18-128.el5 on an i686

login: root

Password:

Login incorrect

默認情況下root用戶是不能登錄的,出於安全考慮.那麼在伺服器上新建一個用戶試試.

[root@rhel ~]# useradd rhel

[root@rhel ~]# passwd rhel

Changing password for user rhel.

New UNIX password:

BAD PASSWORD: it is based on a dictionary word

Retype new UNIX password:

passwd: all authentication tokens updated successfully.

C:\>telnet 192.168.10.10

Red Hat Enterprise Linux Server release 5.3 (Tikanga)

Kernel 2.6.18-128.el5 on an i686

login: rhel

Password:

[rhel@rhel ~]$

已經成功登錄.這裡要注意的是如果一個用戶沒有設置密碼是不能登錄的.當然,沒有密碼的用戶在linux本地也是不能登錄的.那怎麼讓root用戶能登錄呢?

[root@rhel ~]# mv /etc/securetty /etc/securetty.bak //重命名

Red Hat Enterprise Linux Server release 5.3 (Tikanga)

Kernel 2.6.18-128.el5 on an i686

login: root

Password:

Last login: Sat Apr 10 19:39:08 on :0

[root@rhel ~]# whoami

root

其實根本沒有必要允許telnet用戶登錄,使用普通用戶登錄后可以使用su來切換身份.

Red Hat Enterprise Linux Server release 5.3 (Tikanga)

Kernel 2.6.18-128.el5 on an i686

login: rhel

Password:

Last login: Mon Apr 12 11:26:16 from 192.168.10.254

[rhel@rhel ~]$ su root

Password:

[root@rhel rhel]# whoami

root

[root@rhel rhel]#

限制特定用戶使用telnet

service telnet

{

flags = REUSE

socket_type = stream

wait = no

user = root

server = /usr/sbin/in.telnetd

log_on_failure

= USERID

disable = no //是否禁用telnet

protocol = tcp //指定協議

port = 23 //指定埠號

bind = 192.168.10.10 //綁定到某個主機(也可是介面,但要先指定協議和埠.)

access_times = 12:00-13:00 //指定允許訪問的時間

only_from = 192.168.10.0/24 //可以訪問的地址

no_access = 192.168.10.[20,30] //不能訪問的地址

instances = 2 //客戶機最大併發連接數

banner = /banner1 //在連接時顯示的信息,/banner1是文件路徑.

banner_success

= /banner2 //在成功連接時顯示的信息,同樣跟文件路徑.

banner_fail = /banner3 //在不能連接時顯示的信息,同樣跟文件路徑.

}

[root@rhel ~]# touch /banner1 /banner2 /banner3;vi /banner1

welcome

[root@rhel ~]# vi /banner2

welcome to rhel

[root@rhel ~]# vi /banner3

you are no authentication

[root@rhel ~]# date -s "20100421 12:22:38" //修改時間

[root@rhel ~]# service xinetd restart

測試.(略)

如果要更改telnet埠號,可以在/etc/services更改.

SSH

基本配置:

linux系統一般默認安裝ssh,查看本機是否安裝ssh.

[root@rhel ~]# rpm -qa | grep ssh

openssh-4.3p2-29.el5 //ssh核心文件.

openssh-server-4.3p2-29.el5 //ssh伺服器軟體包.

openssh-clients-4.3p2-29.el5 //ssh客戶端軟體包.

openssh-askpass-4.3p2-29.el5 //支持對話框的顯示,一個基於X系統的密碼診斷工具.

ssh配置文件:

有兩個配置文件,/etc/ssh/ssh_config為客戶端配置文件,/etc/ssh/sshd_config為伺服器端的配置文件.

客戶端配置文件:

[root@rhel2 ~]# vi /etc/ssh/ssh_config

# Host * //設定配置文件生效的主機,*代表所有主機.

# ForwardAgent no

//如果存在驗證代理,可以設置連接是否經過驗證代理轉發給遠程計算機.

# ForwardX11 no //設置X11連接是否被自動重定向到安全的通道和顯示集.

# RhostsRSAAuthentication no //設置是否使用RSA演算法的基於rhosts安全驗證.

# RSAAuthentication yes // 設置是否使用RSA演算法進行安全驗證.

# PasswordAuthentication yes

//設置是否使用口令認證.

# HostbasedAuthentication no //基於主機的認證.

# BatchMode no //如果設置為yes,passphrase/password的提示將被禁止.當不能互動式輸入口令的時候,這個選項對腳本文件和批處理任務非常有用.

# CheckHostIP yes //設置ssh是否查看連接到伺服器的主機ip來防止DNS欺騙.

# AddressFamily any //指定ssh應當使用哪種地址簇.

# ConnectTimeout 0 //設置連接超時.

# StrictHostKeyChecking ask //如果設置為yes,ssh就不會自動把計算機的密匙加入$home/.ssh/known_hosts文件,並且一旦計算機的密匙發生變化,就拒絕連接.

# IdentityFile ~/.ssh/identity //設置從哪個文件讀取用戶的RSA安全驗證標識.

# IdentityFile ~/.ssh/id_rsa

# IdentityFile ~/.ssh/id_dsa

# Port 22 //設置連接到遠程主機的埠.

# Protocol 2,1 //設置客戶端使用的ssh版本.

# Cipher 3des //設置加密方式.

#

Ciphers aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour,aes192-cbc,aes256-cbc //指定ssh-2允許使用的加密演算法.

# EscapeChar ~ //設置escape字體.

# Tunnel no //設置穿越不被信任的網路.

# TunnelDevice any:any

# PermitLocalCommand no

伺服器端配置文件:

[root@rhel2 ~]# vi /etc/ssh/sshd_config

#Port 22 //指定ssh監聽的埠

#Protocol 2,1 //設定ssh版本

Protocol 2

#AddressFamily any

#ListenAddress 0.0.0.0 //設置伺服器綁定的ip地址,0.0.0.0表示監聽所有地址

#ListenAddress ::

# HostKey for protocol version 1

#HostKey /etc/ssh/ssh_host_key //設置包含私匙的文件

# HostKeys for protocol version 2

#HostKey /etc/ssh/ssh_host_rsa_key

#HostKey /etc/ssh/ssh_host_dsa_key

# Lifetime and size of ephemeral version 1 server key

#KeyRegenerationInterval 1h

#ServerKeyBits 768 //定義伺服器密匙長度

# Logging

# obsoletes QuietMode and FascistLogging

#SyslogFacility AUTH //設置在記錄來自sshd的消息時是否給出facility code

SyslogFacility AUTHPRIV

#LogLevel INFO //設置記錄sshd日誌消息的層次

# Authentication:

#LoginGraceTime 2m //如果用戶不能成功登錄,在切斷連接之前伺服器需要等待的時間

#PermitRootLogin yes //設置root是否能夠使用ssh登錄

#StrictModes yes //ssh在接收登錄請求之前是否檢查用戶家目錄和rhosts文件的許可權和所有權,防止目錄和文件設置成任何人都有寫的許可權

#MaxAuthTries 6

#RSAAuthentication yes //設置是否允許只有RSA安全驗證

#PubkeyAuthentication yes

#AuthorizedKeysFile .ssh/authorized_keys

# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts

#RhostsRSAAuthentication no //設置是否允許使用rhosts/etc/hosts.equiv加上RSA進行安全驗證

# similar for protocol version 2

#HostbasedAuthentication no

# Change to yes if you don't trust ~/.ssh/known_hosts for

# RhostsRSAAuthentication and HostbasedAuthentication

#IgnoreUserKnownHosts no

# Don't read the user's ~/.rhosts and ~/.shosts files

#IgnoreRhosts yes //設置驗證的時候是否使用rhostsshosts文件

# To disable tunneled clear text passwords, change to no here!

#PasswordAuthentication yes //設置是否允許口令驗證

#PermitEmptyPasswords no //設置是否允許空密碼用戶登錄

PasswordAuthentication yes

# Change to no to disable s/key passwords

#ChallengeResponseAuthentication yes

ChallengeResponseAuthentication no

# Kerberos options

#KerberosAuthentication no

#KerberosOrLocalPasswd yes

#KerberosTicketCleanup yes

#KerberosGetAFSToken no

# GSSAPI options

#GSSAPIAuthentication no

GSSAPIAuthentication yes

#GSSAPICleanupCredentials yes

GSSAPICleanupCredentials yes

# Set this to 'yes' to enable PAM authentication, account processing,

# and session processing. If this is enabled, PAM authentication will

# be allowed through the ChallengeResponseAuthentication mechanism.

# Depending on your PAM configuration, this may bypass the setting of

# PasswordAuthentication, PermitEmptyPasswords, and

# "PermitRootLogin without-password". If you just want the PAM account and

# session checks to run without PAM authentication, then enable this but set

# ChallengeResponseAuthentication=no

#UsePAM no

UsePAM yes

# Accept locale-related environment variables

AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES

AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT

AcceptEnv LC_IDENTIFICATION LC_ALL

#AllowTcpForwarding yes

#GatewayPorts no

#X11Forwarding no

X11Forwarding yes //設置是否允許x11轉發

#X11DisplayOffset 10

#X11UseLocalhost yes

#PrintMotd yes //設置sshd是否在用戶登錄時顯示/etc/motd中的信息

#PrintLastLog yes

#TCPKeepAlive yes

#UseLogin no

#UsePrivilegeSeparation yes

#PermitUserEnvironment no

#Compression delayed

#ClientAliveInterval 0

#ClientAliveCountMax 3

#ShowPatchLevel no

#UseDNS yes

#PidFile /var/run/sshd.pid

#MaxStartups 10

#PermitTunnel no

# no default banner path

#Banner /some/path

# override default of no subsystems

Subsystem sftp /usr/libexec/openssh/sftp-server

TELNET綜合配置實例.

配置telnet伺服器,要求如下

伺服器IP為:192.168.100.209

綁定到eth0介面的5000埠上

能讓root登錄

允許

192.168.100.0網段的訪問

不允許192.168.100.100-192.168.100.110機器訪問

不允許192.168.100.200-192.168.100.210機器訪問

最大連接數為100,每客戶的最大連接為10

限制客戶最大連接速度為50,當超過50時連接中斷20s

設置管理服務的用戶為root,組為root

設置訪問時間為8:00-12:00,14:00-18:00

禁止訪問時間為00:00-8:00,12:00-14:00,18:00-24:00

設置telnet服務佔用伺服器的最大內存為16M,佔用cpu最高為30

設置登錄失敗日誌記錄內容為客戶端主機,用戶名

設置登錄成功日誌記錄內容為客戶端進程ID,主機,用戶名

設置客戶機連接時顯示的歡迎信息,'welcome to RHEL 5'

設置客戶機成功登錄時顯示的信息,'You successfully login to the Telnet Server'

設置客戶機登錄失敗時顯示的信息,'You login failed,Please enter the correct user name and password'

配置步驟:

[root@rhel2 ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0

BOOTPROTO=static

IPADDR=192.168.100.209

NETMASK=255.255.255.0

[root@rhel2 ~]# rpm -ivh /misc/cd/Server/telnet-server-0.17-39.el5.i386.rpm

[root@rhel2 ~]# vi /etc/services

telnet 5000/tcp

telnet 5000/udp

[root@rhel2 ~]# mv /etc/securetty /etc/securetty.bak

[root@rhel2 ~]# vi /etc/xinetd.d/telnet

service telnet

{

flags = REUSE

socket_type = stream

wait = no

user = root

group = root

protocol = tcp

port = 5000

server = /usr/sbin/in.telnetd

log_on_failure = USERID

disable

= no

only_from = 192.168.100.0/24

no_access = 192.168.100.{100,101,102,104,105,106,107,108,109,110,200,201,202,203,204,205,206,207,208,209,210}

這裡應該有簡寫的方法,但我嘗試了很多方法就是不行,以後知道了再改

access_times = 8:00-12:00 14:00-18:00

有了允許時間,也就不需要寫拒絕時間了

log_on_failure

= host userid

log_on_success = pid host userid

rlimit_cpu = 30

rlimit_as = 16M

banner = /banner1

banner_success = /banner2

banner_fail = /banner3

instances = 100

per_source

= 10

cps = 50 20

}

[root@rhel2 ~]# touch /banner1 /banner2 /banner3; vi /banner1

welcome to RHEL 5

[root@rhel2 ~]# vi /banner2

You successfully login to the Telnet Server

[root@rhel2 ~]# vi /banner3

You login failed, Please enter the correct user name and password

[root@rhel2 ~]# service xinetd restart

接下來,允許客戶端訪問.

[root@rhel2 ~]# iptables -I INPUT -p tcp --dport 5000 -j ACCEPT

上面配置文件里的不能訪問地址也可以使用/etc/hosts.allow/etc/hosts.deny兩個文件來實現.配置如下:

允許192.168.100網段訪問而100,101,102,103不能訪問.

[root@rhel2 ~]# vi /etc/hosts.allow

in.telnetd:192.168.100. EXCEPT 192.168.100.100

in.telnetd:192.168.100. EXCEPT 192.168.100.101

這樣編寫這一個文件就可以了,也可以編寫兩個文件,如:

[root@rhel2 ~]# vi /etc/hosts.allow

in.telnetd:192.168.100.111

[root@rhel2 ~]# vi /etc/hosts.deny

in.telnetd:ALL

/etc/hosts.allow裡面存放的是允許訪問的主機,而/etc/hosts.deny裡面放的是拒絕訪問的主機,如果這個文件里寫成ALL:ALL那就是所有人都不能訪問所有服務了,這時就要在

/etc/hosts.allow中添加允許訪問的主機,只要沒有出現在允許訪問列表中的主機一律拒絕,這樣也增強了安全性.如果這兩個文件存在岐義,就以/etc/hosts.allow中的優先,舉例說明:如果在允許列表中允許一台主機訪問,以在拒絕列表中拒絕了這台主機的訪問,那麼這台主機是可以訪問的.

完成,測試.


[火星人 ] LINUX-TELNET/SSH配置已經有769次圍觀

http://coctec.com/docs/linux/show-post-50834.html