1. dnf安裝ssh
dnf -y install ssh
2. 啟動ssh
service sshd start
3.開機自動運行啟動
chkconfig sshd on
4.ssh文件配置
[root@linux234 ~]# vi /etc/ssh/sshd_config ← 用vi打開SSH的配置文件
#Protocol 2,1 ← 找到此行將行頭“#”刪除,再將行末的“,1”刪除,只允許SSH2方式的連接
↓
Protocol 2 ← 修改后變為此狀態,僅使用SSH2
#ServerKeyBits 768 ← 找到這一行,將行首的“#”去掉,並將768改為1024 Centos 6.8默認已經是1024了
↓
ServerKeyBits 1024 ← 修改后變為此狀態,將ServerKey強度改為1024比特
#PermitRootLogin yes ← 找到這一行,將行首的“#”去掉,並將yes改為no
↓
PermitRootLogin no ← 修改后變為此狀態,不允許用root進行登錄
#PasswordAuthentication yes ← 找到這一行,將yes改為no
↓
PasswordAuthentication no ← 修改后變為此狀態,不允許密碼方式的登錄
#PermitEmptyPasswords no ← 找到此行將行頭的“#”刪除,不允許空密碼登錄
↓
PermitEmptyPasswords no ← 修改后變為此狀態,禁止空密碼進行登錄
然后保存並退出。(vi保存退出的命令為ZZ 或按下ESC 在: 就是冒號。[root@linux234 ~]#:wq! )
安全方面
啟用內網網段可訪問 禁止其他
[root@linux234 ~]# vi /etc/hosts.deny ← 修改屏蔽規則,在文尾添加相應行
# 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 ← 添加這一行,屏蔽來自所有的SSH連接請求
[root@linux234 ~]# vi /etc/hosts.allow ← 修改允許規則,在文尾添加相應行
#
# 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. ← 添加這一行,只允許來自內網的SSH連接請求
或指定一個IP,多個IP用逗號分開
重新啟動SSH
service sshd restart 或/etc/init.d/ssh restart
[root@linux234 ~]#service sshd restart
Stopping sshd: [ OK ]
Starting sshd: [ OK ] ← SSH服務器重新啟動成功
登錄服務器
1.Linux客戶機
# ssh IP地址 //輸入服務器IP登錄,不加用戶名默認以root身份登錄
或者
# ssh yonghu1@IP //以yonghu1身份登入服務器
ssh -p 端口 yonghu1@IP