摘要: 任何教程都不如實戰(zhàn)來的快,Window or Mac 登錄樹莓派
ssh登陸樹莓派
樹莓派連接網(wǎng)絡(luò)并啟動SSH服務(wù)
檢查網(wǎng)絡(luò)鏈接狀態(tài),是否ping通
ping www.baidu.com
啟動ssh服務(wù)
通過樹莓派圖形化配置文件菜單
打開配置菜單
sudo raspi-config


選擇第五項,敲擊回車

選擇 SSH

Tab鍵可以用來選擇"Yes" or "No",選擇"Yes",敲擊回車。
第一次配置,pi會自動重啟。
Window操作系統(tǒng)
需要連接網(wǎng)絡(luò)。
下載PuTTy程序,無需安裝,直接打開PuTTy運行

紅色劃線處輸入你的樹莓派的ip,其他選項默認(rèn)。大部分人建議設(shè)置為靜態(tài)IP,避免pi重啟后被分配了新的IP。我使用的是動態(tài)的。默認(rèn)情況家庭網(wǎng)絡(luò)每個設(shè)備都會固定分配一個IP不會變。
打開,跳轉(zhuǎn)到命令提示窗口,輸入你的 pi的名字及pwd即可登錄。
遇到的問題:ssh登錄時,一直提示time out。
解決方法:根目錄/下的boot目錄,創(chuàng)建一個空間文件 touch ssh,重啟pi就ok了。
ssh登錄樹莓派,命令行
ssh pi@192.168.1.199
localhost:~ name$ ssh pi@192.168.1.199
The authenticity of host '192.168.1.199(192.168.1.199)' can't be established.
ECDSA key fingerprint is SHA256:lhyK6WRHKHCQEXNuzgCm+97J6mx24WW/V4/xWIhuF88.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.199' (ECDSA) to the list of known hosts.
pi@192.168.1.1pp's password:
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extentpermitted by applicable law.Last login: Mon Apr 10 18:03:18 2017
pi@raspberrypi:~ $
警告你確實要登錄192.168.1.199樹莓派么
yes
輸入密碼
進(jìn)入樹莓派
ssh登錄Mac
Mac系統(tǒng)預(yù)裝有SSH程序,默認(rèn)是ssh服務(wù)是關(guān)閉狀態(tài)。
查看ssh服務(wù)狀態(tài)
不需要輸入密碼
如果已經(jīng)開啟的話,指令會顯示 "Remote Login: On",反之就會顯示"Remote Login: Off"
方式一:
命令
sudo launchctl list |grep ssh
localhost:/ wangliang$ sudo launchctl list |grep ssh
- 0 com.openssh.sshd
如上,說明ssh服務(wù)啟動成功。
方式二:
命令
sudo systemsetup -getremotelogin
ex:
localhost:~ xxx$ sudo systemsetup -getremotelogin
Password:
Remote Login: On
目前我的Mac ssh服務(wù)是開啟狀態(tài)!
關(guān)閉ssh服務(wù)
命令
sudo systemsetup -setremotelogin off
ex:
localhost:~ xxx$ sudo systemsetup -setremotelogin off
Password:
Do you really want to turn remote login off? If you do, you will lose this connection and can only turn it back on locally at the server (yes/no)? y
Do you really want to turn remote login off? If you do, you will lose this connection and can only turn it back on locally at the server (yes/no)? yes
localhost:~ wangliang$
啟動ssh服務(wù)
方式一:
命令
sudo systemsetup -setremotelogin on
方式二:
命令
sudo launchctl load -w /System/Library/LaunchDaemons/ssh.plist
ex:
localhost:/ wangliang$ sudo launchctl load -w /System/Library/LaunchDaemons/ssh.plist
scp命令
mac下ssh登錄樹莓派,拷貝樹莓派上的文件到本地。
pi@xiaoxiao:/usr/share/nginx/html/yunchuang.zhijia.com$ scp php_mysql/ wangliang@192.168.1.101:/home/wangliang/
The authenticity of host '192.168.1.101 (192.168.1.101)' can't be established.
ECDSA key fingerprint is 2f:5a:78:03:9e:3a:52:c5:70:ea:70:a4:cf:23:3d:ba.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.101' (ECDSA) to the list of known hosts.
Password:
php_mysql: not a regular file
pi@xiaoxiao:/usr/share/nginx/html/yunchuang.zhijia.com$ scp php_mysql/ wangliang@192.168.1.101:~/
Password:
php_mysql: not a regular file
pi@xiaoxiao:/usr/share/nginx/html/yunchuang.zhijia.com$
注意這句php_mysql: not a regular file不是一個常規(guī)文件,說明目前還不能直接copy整個目錄
pi@xiaoxiao:/usr/share/nginx/html/yunchuang.zhijia.com$ scp php_mysql/create_db.php wangliang@192.168.1.101:~/
Password:create_db.php 100% 338 0.3KB/s 00:00
好了,一次copy一個文件。