ssh命令登陆设备

摘要: 任何教程都不如实战来的快,Window or Mac 登录树莓派

ssh登陆树莓派

树莓派连接网络并启动SSH服务

检查网络链接状态,是否ping通

ping www.baidu.com

启动ssh服务
通过树莓派图形化配置文件菜单
打开配置菜单

sudo  raspi-config
ssh命令登陆设备_第1张图片
打开树莓派配置

ssh命令登陆设备_第2张图片
配置菜单项

选择第五项,敲击回车


ssh命令登陆设备_第3张图片
选择5

选择 SSH
ssh命令登陆设备_第4张图片
选择SSH选项

Tab键可以用来选择"Yes" or "No",选择"Yes",敲击回车。
第一次配置,pi会自动重启。
Window操作系统
需要连接网络。
下载PuTTy程序,无需安装,直接打开PuTTy运行

ssh命令登陆设备_第5张图片
PuTTy界面

红色划线处输入你的树莓派的ip,其他选项默认。大部分人建议设置为静态IP,避免pi重启后被分配了新的IP。我使用的是动态的。默认情况家庭网络每个设备都会固定分配一个IP不会变。
打开,跳转到命令提示窗口,输入你的 pi的名字及pwd即可登录。
遇到的问题:ssh登录时,一直提示time out。
解决方法:根目录/下的boot目录,创建一个空间文件 touch ssh,重启pi就ok了。

ssh登录树莓派,命令行

ssh [email protected]
localhost:~ name$ ssh [email protected]
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.
[email protected]'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
输入密码
进入树莓派

ssh登录Mac

Mac系统预装有SSH程序,默认是ssh服务是关闭状态。

查看ssh服务状态

不需要输入密码

如果已经开启的话,指令会显示 "Remote Login: On",反之就会显示"Remote Login: Off"

方式一:

命令
sudo launchctl list |grep ssh


localhost:/ wangliang$ sudo launchctl  list |grep ssh

-   0   com.openssh.sshd

如上,说明ssh服务启动成功。

方式二:

命令
sudo systemsetup -getremotelogin


ex:

localhost:~ xxx$ sudo systemsetup -getremotelogin
Password:
Remote Login: On

目前我的Mac ssh服务是开启状态!

关闭ssh服务

命令

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服务

方式一:

命令
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/  [email protected]:/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/  [email protected]:~/

Password:

php_mysql: not a regular file

pi@xiaoxiao:/usr/share/nginx/html/yunchuang.zhijia.com$

注意这句php_mysql: not a regular file不是一个常规文件,说明目前还不能直接copy整个目录


pi@xiaoxiao:/usr/share/nginx/html/yunchuang.zhijia.com$ scp php_mysql/create_db.php  [email protected]:~/

Password:create_db.php                                                            100%  338    0.3KB/s  00:00

好了,一次copy一个文件。

你可能感兴趣的:(ssh命令登陆设备)