Mac 上玩 Linux(一)安裝Ubuntu
Mac 上玩 Linux(二)Ubuntu 支持 root 登錄
Mac 上玩 Linux(三)使用 SSH 連接 Ubuntu
Mac 上玩 Linux(四)安裝 VMware Tools
首先 Mac 不像 Windows 需要類似 XShell 這樣的客戶端進(jìn)行 SSH 連接,直接使用終端即可岔激。
一齿尽、首先查看 IP 地址
我這里是使用的 Ubuntu 18.04 的模擬器血崭。
-
輸入命令:
ifconfig
-
需要安裝 net-tools:
apt install net-tools
-
安裝成功后仍源,再次
ifconfig
二钧大、ssh 登錄
- ssh 登錄 root 用戶
使用ssh root@IP地址
或者ssh -p 22 root@IP地址
命令
出現(xiàn)錯(cuò)誤:? ~ ssh root@192.168.139.129 ssh: connect to host 192.168.139.129 port 22: Connection refused ? ~ ssh -p 22 root@192.168.139.129 ssh: connect to host 192.168.139.129 port 22: Connection refused
- 檢查服務(wù)端 ssh 服務(wù)是否開啟
沒有找到 sshd 蛤迎,說明 ssh 服務(wù)沒有啟動(dòng),需要開啟 ssh 服務(wù)刊懈。ps -e | grep sshd
三逗爹、啟動(dòng)服務(wù)器的 ssh
- 開啟 ssh 服務(wù)
service ssh start
- 更新源列表
apt-get update
- 安裝 openssh-server
apt-get install openssh-server
- 再次查看 ssh 服務(wù)是否啟動(dòng)
四擎宝、ssh 登錄
- 連接 root 用戶
? ~ ssh root@192.168.139.129
The authenticity of host '192.168.139.129 (192.168.139.129)' can't be established.
ECDSA key fingerprint is SHA256:rVB8kHFOI0hCUyibvY6w5TfDF6I+5z0qG2jcVIxi94c.
Are you sure you want to continue connecting (yes/no)? yes
- 輸入 root 用戶密碼
Warning: Permanently added '192.168.139.129' (ECDSA) to the list of known hosts.
root@192.168.139.129's password:
- 權(quán)限被拒絕
Permission denied, please try again.
這種情況束析,很大的可能是由于服務(wù)器默認(rèn)禁止 root 用戶進(jìn)行 ssh 遠(yuǎn)程登錄申尤。
- 嘗試普通用戶登錄滚粟,排除配置問題
? ~ ssh ff@192.168.139.129
ff@192.168.139.129's password:
- 輸入用戶密碼寻仗,普通用戶登錄成功。
Welcome to Ubuntu 18.04.2 LTS (GNU/Linux 4.18.0-17-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
* Canonical Livepatch is available for installation.
- Reduce system reboots and improve kernel security. Activate at:
https://ubuntu.com/livepatch
167 個(gè)可升級軟件包凡壤。
75 個(gè)安全更新署尤。
Your Hardware Enablement Stack (HWE) is supported until April 2023.
The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.
ff@FF-VM:~$
到這里就基本確定了就是,服務(wù)器禁止 root 用戶進(jìn)行 ssh 遠(yuǎn)程登錄了亚侠。
五曹体、允許 root 用戶 ssh 登錄
- 修改 sshd_config
注意,安裝了 openssh 才會有這個(gè)文件硝烂,如果文件不存在請檢查是否安裝了 openssh箕别。
vim /etc/ssh/sshd_config
- 配置 PermitRootLogin
- 檢查是否有
PermitRootLogin
- 存在
PermitRootLogin ...
的話(...
代表任何語句),全部修改為PermitRootLogin yes
- 不存在
PermitRootLogin
的話滞谢,增加PermitRootLogin yes
不過這里有問題串稀,正常情況下 PermitRootLogin
應(yīng)該也是黃色高亮的。
我嘗試了多次狮杨,還是不能高亮母截,不管了先保存。
- 重啟 ssh 服務(wù)
/etc/init.d/ssh restart
- 連接 root 用戶
? ~ ssh root@192.168.139.129
root@192.168.139.129's password:
Permission denied, please try again.
依然權(quán)限被拒絕禾酱,說明配置 PermitRootLogin yes
沒有生效微酬。
六绘趋、重新安裝 openssh-server
大多數(shù)情況下,完成上一步就可以完成登錄了颗管,是不需要該步驟的陷遮。
- 卸載 openssh-server
apt-get purge openssh-server
- 刪除 sshd_config
rm /etc/ssh/sshd_config
- 更新源列表
apt-get update
- 安裝 openssh-server
apt-get install openssh-server
- 打開 sshd_config
vim /etc/ssh/sshd_config
- 配置 PermitRootLogin
- 啟動(dòng) ssh 服務(wù)
/etc/init.d/ssh start
七、 ssh 登錄
連接 root 用戶
? ~ ssh root@192.168.139.129
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
SHA256:5devwrE/cIsO8P0l9nc7zQ+xxKRO5BIUDZ1tjd8BB+0.
Please contact your system administrator.
Add correct host key in /Users/ff/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /Users/ff/.ssh/known_hosts:5
ECDSA host key for 192.168.139.129 has changed and you have requested strict checking.
Host key verification failed.
出現(xiàn)錯(cuò)誤的原因是垦江,重裝了 openssh-server 帽馋,服務(wù)器的公鑰發(fā)生了變化導(dǎo)致的錯(cuò)誤。
SSH 服務(wù)是通過公鑰和私鑰來進(jìn)行連接的比吭,它會把每個(gè)曾經(jīng)訪問過計(jì)算機(jī)或服務(wù)器的公鑰绽族,記錄在 known_hosts 中,當(dāng)下次訪問曾經(jīng)訪問過的計(jì)算機(jī)或服務(wù)器時(shí)衩藤,SSH 就會核對公鑰吧慢,如果和上次記錄的不同,OpenSSH 會發(fā)出警告赏表。
八检诗、修改客戶端 known_hosts 文件
根據(jù)提示進(jìn)行修改
Add correct host key in /Users/ff/.ssh/known_hosts to get rid of this message.
- 進(jìn)入 known_hosts
? ~ vim /Users/ff/.ssh/known_hosts
- 找到以 192.168.139.129 起始的行,將正行刪除
192.168.139.129 ecdsa-sha2-nistp256 ...省略
九瓢剿、ssh 登錄
- 連接 root 用戶
? ~ ssh root@192.168.139.129
The authenticity of host '192.168.139.129 (192.168.139.129)' can't be established.
ECDSA key fingerprint is SHA256:5devwrE/cIsO8P0l9nc7zQ+xxKRO5BIUDZ1tjd8BB+0.
Are you sure you want to continue connecting (yes/no)? yes
- 輸入 root 用戶密碼
Warning: Permanently added '192.168.139.129' (ECDSA) to the list of known hosts.
root@192.168.139.129's password:
- root 用戶登錄成功
Welcome to Ubuntu 18.04.2 LTS (GNU/Linux 4.18.0-20-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
* Canonical Livepatch is available for installation.
- Reduce system reboots and improve kernel security. Activate at:
https://ubuntu.com/livepatch
0 個(gè)可升級軟件包逢慌。
0 個(gè)安全更新。
Your Hardware Enablement Stack (HWE) is supported until April 2023.
The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.
root@FF-VM:~#