[关闭]
@zifehng 2017-06-14T07:34:37.000000Z 字数 3350 阅读 977

Ubuntu开发环境搭建记录

Ubuntu ssh smb adb minicom


本文基于Ubuntu16.04LTS,其他版本仅供参考

1. 使用ssh登陆服务器

ssh命令用法:

  1. ssh user@hostname -p port

user为用户名;hostname可以为服务器ip地址;-p选项指定端口号,如果不添加-p选项,则默认以22号端口登陆服务器。

在本文中我以“dept”用户身份登陆ip地址为192.168.1.200的服务器:

  1. $ ssh dept@192.168.1.200

输入上述命令后,再按照提示输入密码,最后成功登陆服务器。

但是每次登陆服务器都要输入密码太麻烦了,有没有更好的解决方案呢?在网上找到了两种方案:

使用sshpass -p参数指定明文登陆密码“123456”:

  1. $ sshpass -p 123456 ssh dept@192.168.1.200

然后将上述命令写入脚本中,每次以脚本登陆服务器。

使用ssh-keygen生成公钥和私钥文件:

  1. $ ssh-keygen -t rsa

密钥文件路径:~/.ssh,私钥文件为id_rsa,公钥文件为id_rsa.pub,
将公钥文件内容添加至服务器文件~/.ssh/authorized_keys中:

  1. $ cat id_rsa.pub >> ~/.ssh/authorized_keys

有了密钥配对后,使用ssh登陆服务器就不需要密码了

2. 使用smb访问服务器共享目录

服务器smb共享目录“projector”,使用如下命令将其挂载至本地“/media/P”目录:

  1. $ mount -t cifs //192.168.1.200/projector /media/P -o username=root,password=123456

将命令保存为脚本文件mount_projector.sh,然后加入/etc/rc.local,这样就能实行开机自动挂载smb共享目录:

  1. #!/bin/sh -e
  2. #
  3. # rc.local
  4. #
  5. # This script is executed at the end of each multiuser runlevel.
  6. # Make sure that the script will "exit 0" on success or any other
  7. # value on error.
  8. #
  9. # In order to enable or disable this script just change the execution
  10. # bits.
  11. #
  12. # By default this script does nothing.
  13. # mount smb floder --add by wangshusheng
  14. /home/wangshusheng/mount_projector.sh
  15. exit 0
  16. if [-x /usr/bin/numlockx ]; then
  17. numlockx on
  18. fi

3. adb连接usb设备调试

1. 安装adb工具

  1. $ sudo add-apt-repository ppa:nilarimogard/webupd8
  2. $ sudo apt-get update
  3. $ sudo apt-get install android-tools-adb

2. 确认usb设备ID信息
通过插拔usb设备,使用两次lsusb命令对比找出设备ID信息:

  1. $ lsusb
  2. Bus 002 Device 002: ID 8087:8000 Intel Corp.
  3. Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
  4. Bus 001 Device 002: ID 8087:8008 Intel Corp.
  5. Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
  6. Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
  7. Bus 003 Device 001: ID 2207:0010
  8. Bus 003 Device 003: ID 093a:2510 Pixart Imaging, Inc. Optical Mouse
  9. Bus 003 Device 002: ID 14cd:8601 Super Top
  10. Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
  1. $ lsusb
  2. Bus 002 Device 002: ID 8087:8000 Intel Corp.
  3. Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
  4. Bus 001 Device 002: ID 8087:8008 Intel Corp.
  5. Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
  6. Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
  7. Bus 003 Device 003: ID 093a:2510 Pixart Imaging, Inc. Optical Mouse
  8. Bus 003 Device 002: ID 14cd:8601 Super Top
  9. Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
  1. Bus 003 Device 001: ID 2207:0010

3. 创建文件/etc/udev/rules.d/70-android.rules,输入设备ID信息

  1. SUBSYSTEM=="usb", ATTRS{idVendor}=="2207", ATTRS{idProduct}=="0010",MODE="0666"

4. 修改权限

  1. $ sudo chmod a+r /etc/udev/rules.d/70-android.rules

5. 重启udev

  1. $ /etc/init.d/udev restart

6. 重启adb服务

  1. $ adb kill-server
  2. $ adb start-server

4. minicom连接串口设备调试

1. 安装minicom

  1. $ sudo apt-get install minicom

2. 配置minicom
输入命令:

  1. $ sudo minicom -s

弹出配置选项框:

  1. +-----[configuration]------+
  2. | Filenames and paths |
  3. | File transfer protocols |
  4. | Serial port setup |
  5. | Modem and dialing |
  6. | Screen and keyboard |
  7. | Save setup as dfl |
  8. | Save setup as.. |
  9. | Exit |
  10. | Exit from Minicom |
  11. +--------------------------+

选择Serial port setup,因为我使用了usb转串口连接,因此串口设备配置为“/dev/ttyUSB0”,波特率配置为“115200”,数据为/奇偶校验/停止位配置为“8N1”:

  1. +----------------------------------------------------------------+
  2. | A - Serial Device : /dev/ttyUSB0 |
  3. | B - Lockfile Location : /var/lock |
  4. | C - Callin Program : |
  5. | D - Callout Program : |
  6. | E - Bps/Par/Bits : 115200 8N1 |
  7. | F - Hardware Flow Control : No |
  8. | G - Software Flow Control : No |
  9. | |
  10. | Change which setting? |
  11. +----------------------------------------------------------------+

3. 为minicom增加特殊权限
因为设备节点"/dev/ttyUSB0"权限所限,每次使用minicom都要切换至root身份,因此使用chmod命令为其增加特殊权限位“s”,这样在普通用户身份下也能执行minicom了:

  1. sudo chmod a+s /usr/bin/minicom

4. 打开ANSI转移序列色彩支持
linux终端支持标准ANSI转义序列色彩,但minicom是默认关闭的,使用如下命令可以在启动minicom时打开此选项:

  1. minicom -c on
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注