安裝SSH
yum install ssh
啟動(dòng)SSH
service sshd start
設(shè)置開機(jī)運(yùn)行
chkconfig sshd on
SSH相關(guān)配置文件的修改
首先修改SSH的配置文件。如下:
[root@sample ~]# vi /etc/ssh/sshd_config ← 用vi打開SSH的配置文件
#Protocol 2,1 ← 找到此行將行頭“#”刪除,再將行末的“,1”刪除,只允許SSH2方式的連接
Protocol 2 ← 修改后變?yōu)榇藸顟B(tài),僅使用SSH2
#ServerKeyBits 768 ← 找到這一行,將行首的“#”去掉,并將768改為1024
ServerKeyBits 1024 ← 修改后變?yōu)榇藸顟B(tài),將ServerKey強(qiáng)度改為1024比特
#PermitRootLogin yes ← 找到這一行,將行首的“#”去掉,并將yes改為no
PermitRootLogin no ← 修改后變?yōu)榇藸顟B(tài),不允許用root進(jìn)行登錄
#PasswordAuthentication yes ← 找到這一行,將yes改為no
PasswordAuthentication no ← 修改后變?yōu)榇藸顟B(tài),不允許密碼方式的登錄
#PermitEmptyPasswords no ← 找到此行將行頭的“#”刪除,不允許空密碼登錄
PermitEmptyPasswords no ← 修改后變?yōu)榇藸顟B(tài),禁?空密碼進(jìn)行登錄
然后保存并退出。(vi保存退出的命令為ZZ)
因?yàn)槲覀冎幌胱孲SH服務(wù)為管理系統(tǒng)提供方便,所以在不通過(guò)外網(wǎng)遠(yuǎn)程管理系統(tǒng)的情況下,只允許內(nèi)網(wǎng)客戶端通過(guò)SSH登錄到服務(wù)器,以最大限度減少不安全因素。設(shè)置方法如下:
[root@sample ~]# vi /etc/hosts.deny ← 修改屏蔽規(guī)則,在文尾添加相應(yīng)行
#
# hosts.deny This file describes the names of the hosts which are
# *not* allowed to use the local INET services, as decided
# by the ‘/usr/sbin/tcpd’ server.
#
# The portmap line is redundant, but it is left to remind you that
# the new secure portmap uses hosts.deny and hosts.allow. In particular
# you should know that NFS uses portmap!
sshd: ALL ← 添加這一行,屏蔽來(lái)自所有的SSH連接請(qǐng)求
[root@sample ~]# vi /etc/hosts.allow ← 修改允許規(guī)則,在文尾添加相應(yīng)行
#
# hosts.allow This file describes the names of the hosts which are
# allowed to use the local INET services, as decided
# by the ‘/usr/sbin/tcpd’ server.
#
sshd: 192.168.0. ← 添加這一行,只允許來(lái)自內(nèi)網(wǎng)的SSH連接請(qǐng)求
netstat -tunlp 查看正在運(yùn)行的端口號(hào)!vim /etc/ssh/sshd_config這個(gè)文件,這里把#Port 22這個(gè)字段前面的#去掉,再把22改成自己要設(shè)的端口就行了,然后重啟ssh服務(wù)。/etc/init.d/sshd restart 假如要限制SSH登陸的IP,那么可以如下做:修改/etc/hosts.deny,在其中加入sshd:ALL修改:/etc/hosts.allow,在其中進(jìn)行如下設(shè)置:sshd:192.168.0.24這樣就可以限制只有192.168.0.241的IP通過(guò)SSH登陸上LINUX機(jī)器了
SSH遠(yuǎn)程連接配置
1.配置IP
#setup
選擇 NetWork configuration
選擇 Device configuration
選擇 eth0
Use DHCP [*] 改 為 [ ] 用空格鍵將*去除
Static IP 輸入 192.168.1.112
Netmask 輸入 255.255.255.0
Default gateway IP 輸入 192.168.1.1
Primary DNS Server 輸入 192.168.1.1
2.改SSH端口
vim /etc/ssh/sshd_config
#Port 22
去#注釋 改 22 為 2200(2000以上)
3.重啟SSH
/etc/init.d/sshd restart
4.重啟網(wǎng)絡(luò)
service network restart
或
/etc/init.d/network restart
5.查看端口
netstat -lnp|more
6.關(guān)防火墻
/etc/init.d/iptables stop
啟動(dòng)SSH
/etc/init.d/sshd start
至此SSH已經(jīng)可以連接了