天天看点

Ubuntu开发环境搭建记录

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

1. 使用ssh登陆服务器

ssh命令用法:

ssh [email protected] -p port
           

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

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

$ ssh [email protected]
           

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

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

  • 方案一:

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

$ sshpass -p  ssh [email protected]
           

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

  • 方案二:

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

$ ssh-keygen -t rsa
           

密钥文件路径:~/.ssh,私钥文件为id_rsa,公钥文件为id_rsa.pub,

将公钥文件内容添加至服务器文件~/.ssh/authorized_keys中:

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

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

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

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

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

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

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# mount smb floder --add by wangshusheng
/home/wangshusheng/mount_projector.sh

exit 
if [-x /usr/bin/numlockx ]; then
numlockx on
fi
           

3. adb连接usb设备调试

1. 安装adb工具

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

2. 确认usb设备ID信息

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

  • 插入usb设备:
$ lsusb
Bus  Device : ID : Intel Corp. 
Bus  Device : ID d6b: Linux Foundation  root hub
Bus  Device : ID : Intel Corp. 
Bus  Device : ID d6b: Linux Foundation  root hub
Bus  Device : ID d6b: Linux Foundation  root hub
Bus  Device : ID : 
Bus  Device : ID a: Pixart Imaging, Inc. Optical Mouse
Bus  Device : ID cd: Super Top 
Bus  Device : ID d6b: Linux Foundation  root hub
           
  • 拔出usb设备:
$ lsusb
Bus  Device : ID : Intel Corp. 
Bus  Device : ID d6b: Linux Foundation  root hub
Bus  Device : ID : Intel Corp. 
Bus  Device : ID d6b: Linux Foundation  root hub
Bus  Device : ID d6b: Linux Foundation  root hub
Bus  Device : ID a: Pixart Imaging, Inc. Optical Mouse
Bus  Device : ID cd: Super Top 
Bus  Device : ID d6b: Linux Foundation  root hub
           
  • 确认设备ID信息:

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

4. 修改权限

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

5. 重启udev

$ /etc/init.d/udev restart
           

6. 重启adb服务

$ adb kill-server
$ adb start-server
           

4. minicom连接串口设备调试

1. 安装minicom

$ sudo apt-get install minicom
           

2. 配置minicom

输入命令:

弹出配置选项框:

+-----[configuration]------+                                        
            | Filenames and paths      |                                        
            | File transfer protocols  |                                        
            | Serial port setup        |                                        
            | Modem and dialing        |                                        
            | Screen and keyboard      |                                        
            | Save setup as dfl        |                                        
            | Save setup as..          |                                        
            | Exit                     |                                        
            | Exit from Minicom        |                                        
            +--------------------------+                                
           

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

+----------------------------------------------------------------+
    | A -    Serial Device      : /dev/ttyUSB0                       |   
    | B - Lockfile Location     : /var/lock                          |   
    | C -   Callin Program      :                                    |   
    | D -  Callout Program      :                                    |   
    | E -    Bps/Par/Bits       :  N1                         |   
    | F - Hardware Flow Control : No                                 |   
    | G - Software Flow Control : No                                 |   
    |                                                                |   
    |    Change which setting?                                       |   
    +----------------------------------------------------------------+
           

3. 为minicom增加特殊权限

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

sudo chmod a+s /usr/bin/minicom
           

4. 打开ANSI转移序列色彩支持

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

minicom -c on