ubuntu默認(rèn)并沒有安裝ssh服務(wù),如果通過ssh鏈接ubuntu,需要自己手動(dòng)安裝ssh-server。判斷是否安裝ssh服務(wù),可以通過如下命令進(jìn)行:
- xjj@xjj-desktop:~$ ssh localhost
- ssh: connect to host localhost port 22: Connection refused
xjj@xjj-desktop:~$ ssh localhost ssh: connect to host localhost port 22: Connection refused
如上所示,表示沒有還沒有安裝,可以通過apt安裝,命令如下:
- xjj@xjj-desktop:~$ sudo apt-get install openssh-server
xjj@xjj-desktop:~$ sudo apt-get install openssh-server
系統(tǒng)將自動(dòng)進(jìn)行安裝,安裝完成以后,先啟動(dòng)服務(wù):
- xjj@xjj-desktop:~$ sudo /etc/init.d/ssh start
xjj@xjj-desktop:~$ sudo /etc/init.d/ssh start
啟動(dòng)后,可以通過如下命令查看服務(wù)是否正確啟動(dòng)
- xjj@xjj-desktop:~$ ps -e|grep ssh
- 6212 ? 00:00:00 sshd
xjj@xjj-desktop:~$ ps -e|grep ssh 6212 ? 00:00:00 sshd
如上表示啟動(dòng)ok。注意,ssh默認(rèn)的端口是22,可以更改端口,更改后先stop,
然后start就可以了。改配置在/etc/ssh/sshd_config下,如下所示。
- xjj@xjj-desktop:~$ vi /etc/ssh/sshd_config
- # Package generated configuration file
- # See the sshd(8) manpage for details
- # What ports, IPs and protocols we listen for
- Port 22
xjj@xjj-desktop:~$ vi /etc/ssh/sshd_config # Package generated configuration file # See the sshd(8) manpage for details # What ports, IPs and protocols we listen for Port 22
最后,應(yīng)該是連接的時(shí)候了。請(qǐng)看如下命令:
xjj@xjj-desktop:~$ ssh exceljava@192.168.158.129