1.安裝ssh
apt-get install openssh-server
2.備份ssh的配置文件
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
3.新裝的ssh需要修改配置文件
vi /etc/ssh/sshd_config
配置文件修改這幾處地方
Port = 22 # 默認(rèn)是22端口,如果和windows端口沖突或你想換成其他的否則不用動(dòng)
#ListenAddress 0.0.0.0 # 如果需要指定監(jiān)聽的IP則去除最左側(cè)的井號(hào),并配置對應(yīng)IP,默認(rèn)即監(jiān)聽PC所有IP
PermitRootLogin no # 如果你需要用 root 直接登錄系統(tǒng)則此處改為 yes
PasswordAuthentication no # 將 no 改為 yes 表示使用帳號(hào)密碼方式登錄
4.啟動(dòng)ssh
service ssh start # * Starting OpenBSD Secure Shell server sshd
# 或者
/etc/init.d/ssh start # * Starting OpenBSD Secure Shell server sshd
如果提示錯(cuò)誤信息中包含could not load host key 則需要重新生成 key
sudo rm /etc/ssh/ssh*key # 先移除舊的key
dpkg-reconfigure openssh-server
生成之后需要重啟SSH服務(wù)使新的密鑰生效:
service ssh restart # * Restarting OpenBSD Secure Shell server sshd
# 或者
/etc/init.d/ssh restart # * Restarting OpenBSD Secure Shell server sshd
啟動(dòng)、停止和重啟ssh的命令如下
/etc/init.d/ssh start # * Starting OpenBSD Secure Shell server sshd
/etc/init.d/ssh stop # * Stopping OpenBSD Secure Shell server sshd
/etc/init.d/ssh restart # * Restarting OpenBSD Secure Shell server sshd
5.查看服務(wù)狀態(tài)
service ssh status
# * sshd is running 顯示此內(nèi)容則表示啟動(dòng)正常
6.查看ssh是否啟動(dòng)
ps -e | grep ssh
如果ssh已經(jīng)啟動(dòng)則會(huì)提示
469 ? 00:00:00 sshd
7.設(shè)置ssh開機(jī)自啟動(dòng)
sudo systemctl enable ssh #說明:sudo是提升權(quán)限,systemctl是服務(wù)管理器,enable是systemctl的參數(shù),表示啟用開機(jī)自動(dòng)運(yùn)行,ssh是要設(shè)置的服務(wù)名稱。
注:如果要設(shè)置開機(jī)禁止啟動(dòng)則
sudo systemctl disable ssh #說明:sudo是提升權(quán)限,systemctl是服務(wù)管理器,disable是systemctl的參數(shù),表示禁止開機(jī)運(yùn)行,ssh是要設(shè)置的服務(wù)名稱。