1.安裝虛擬機工具 vmware workstation
2.創建一個虛擬機,系統版本是:CentOS-6.8-x86_64-LiveDVD
3.系統安裝完成后,選擇網絡為橋接模式,如圖
4.檢查主機與虛擬機上的linux是否互相ping通,在主機上 cmd --> telnet 192.168.1.8(虛擬機ip) 22
(如果主機無法使用telnet命令,則需要打開Telnet客戶端,控制面板 --> 程序 --> 卸載或更改程序 --> 打開或關閉Windows功能 --> 選中 Telnet客戶端)
5.查看linux是否安裝ssh服務
登錄 root 用戶下
命令:ssh localhost
如果提示 "ssh:connect to host localhost port 22:connection refused",就說明沒有打開ssh服務或者未安裝ssh服務.
(1)如果linux系統是 ubuntu linux 版本,執行命令:sudo apt-get install openssh-server 安裝ssh服務,在提示時都選擇yes,然后會自動安裝ssh服務.
(2)如果linux系統是 centos linux 版本,查看ssh是否安裝,執行命令:rpm -qa | grep ssh
如果安裝過ssh服務則會出如圖頁面
如果沒有安裝過ssh服務,則執行命令:yum install openssh-server 安裝
6.安裝完成后輸入命令(root用戶下)
啟動ssh服務命令:service sshd start
重啟SSH服務:service sshd restart
停止ssh服務命令:service sshd stop
查看ssh服務22端口是否啟動命令:netstat -antp | grep sshd
查看ssh服務進程命令:ps -ef|grep ssh
7.設置ssh服務為開機啟動命令:chkconfig sshd on
設置ssh服務禁止開機啟動命令:chkconfig sshd off
8.啟動好ssh服務還是無法連接則要關閉防火牆
#1.查看防火牆狀態,出現下面顯示表示防火牆開啟 [root@localhost ~]# service iptables status Table: filter Chain INPUT (policy ACCEPT) num target prot opt source destination 1 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED 2 ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0
3 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
4 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22
5 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited Chain FORWARD (policy ACCEPT) num target prot opt source destination 1 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited Chain OUTPUT (policy ACCEPT) num target prot opt source destination #2.root用戶下臨時關閉防火牆 [root@localhost ~]# service iptables stop iptables: Setting chains to policy ACCEPT: filter [ OK ] iptables: Flushing firewall rules: [ OK ] iptables: Unloading modules: [ OK ] #3.查看狀態,出現下面信息則防火牆為關閉狀態 [root@localhost ~]# service iptables status iptables: Firewall is not running.
(1)防火牆臨時生效
開啟:service iptables start
關閉:service iptables stop
(2)防火牆永久性生效
開啟:chkconfig iptables on
關閉:chkconfig iptables off
9.設置虛擬機開機不啟動:win+R鍵 --> 輸入 msconfig --> 啟動 --> 把vmware去掉