Linux树莓派

树莓派手动玩(开启SSH,VNC)

2015-01-09  本文已影响42597人  黑夜之旅

========

半年前败了一个树莓派,因为工作很忙所以没时间折腾一下。
最近换工作,确认了offer,赋闲在家,也终于有空摆弄一下树莓派。

(一)启用SSH

我的环境为:Thinkpad(Fedora), TP-Link无线路由,树莓派(debian)一只。
树莓派通过网线连接到无线路由器和电脑处于同一网段,没有显示器的情况下如何确定树莓派的IP呢? 这时候nmap登场:

nmap -v -sP 192.168.1.1/10稍等片刻,然后可以看到Raspberry Pi的设备。

或者用手机上的一款应用Fing也可以扫描本网段的端口。

树莓派默认安装了SSH服务,SSH登录的方式为:ssh pi@树莓派ip地址,默认密码为:raspberry

为了安全, 推荐关闭root用户ssh登录, 方法为修改"/etc/ssh/sshd_config", 将 PermitRootLogin yes 改为 PermitRootLogin no
重启ssh服务: service ssh restart

SSH登录SSH登录

(二)树莓派初始化设置并安装VNC

2.1 在树莓派上配置vnc

### BEGIN INIT INFO
# Provides:          tightvncserver
# Required-Start:    $local_fs
# Required-Stop:     $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start/stop tightvncserver
### END INIT INFO
 
# More details see:
# http://www.penguintutor.com/linux/tightvnc
 
### Customize this entry
# Set the USER variable to the name of the user to start tightvncserver under
export USER='pi'
### End customization required
 
eval cd ~$USER
 
case "$1" in
  start)
    su $USER -c '/usr/bin/tightvncserver -depth 16 -geometry 800x600 :1'
    echo "Starting TightVNC server for $USER "
    ;;
  stop)
    su $USER -c '/usr/bin/tightvncserver -kill :1'
    echo "Tightvncserver stopped"
    ;;
  *)
    echo "Usage: /etc/init.d/tightvncserver {start|stop}"
    exit 1
    ;;
esac
exit 0

然后给增加执行权限,并启动服务:

sudo chmod +x /etc/init.d/tightvncserver
sudo service tightvncserver stop
sudo service tightvncserver start

安装chkconfig, 并将vnc服务设为开机启动:

sudo apt-get install chkconfig
chkconfig --add tightvncserver
chkconfig tightvncserver on

2.2 PC端连接树莓派

打开VNC Viewer, 输入“IP地址:1”,(这里冒号后面的1是指终端号,如果不填则是终端0)然后回车输入密码。


输入IP:终端号输入IP:终端号

注:如果使用终端0,可能会导致下面的错误

unable connect to socket connection refused 111

VNC-ViewerVNC-Viewer

(三)摄像头

树莓派支持两种摄像头,官方的raspberry camera和任何符合UVC标准的USB摄像头。如果要支持摄像头,需要在sudo raspi-config时选择"enable camera".

测试摄像头:

上一篇 下一篇

猜你喜欢

热点阅读