ubuntu 设置

@think3r 2017-11-09 0:3:52

0x-1 待读

  • 换源 : https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/
  • sudo apt-get install git screenfetch neofetch sl cmake cloc ffmpeg tree busybox shellcheck clang figlet unzip unrar
  • sudo apt-get install repo
  • oh-my-zsh
    1. sudo apt-get install zsh && chsh -s /bin/zsh –> 重启
    2. Ubuntu 18.04 LTS下安装zsh和oh-my-zsh
    3. cp ./.rc_add ~/ && echo "\nsource ~/.rc_add" >> ~/.zshrc
    4. cd ~/.oh-my-zsh/custom/plugins
      • git clone https://github.com/zsh-users/zsh-autosuggestions.git
      • git clone https://github.com/zsh-users/zsh-syntax-highlighting.git
  • vim :
    1. cp .vimrc ~/
    2. curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
    3. vim –> PlugUpdate
  • git clone 仓库(Linux 和 git)
  • autojump 和 incr 配置;
  • ssh 配置(手动 U 盘拷贝);

0x00 vmware 虚拟机安装

0x00 vmware 安装 ubuntu 虚拟机

  • Ubuntu 修改用户密码与启动root账号
    • ubuntu 的默认账号不是 root? root 需要单独启用??
  • ssh 相关

  • ubuntu 16.04 设置静态IP
  • linux ssh 开启颜色显示 (WSL 默认即可显示颜色无需更改)
    • 直接复制 .bashrc 中的颜色方案即可. cmder 使用较为方便
      • 编辑 ~/.bashrc,设置 force_color_prompt=yes 即可(找到 force_color_prompt=yes 这一行并删除前面的注释符号
    • 编码与颜色值
    • 设置 ssh 连接时的 shell 配色方案为 ubuntu 自带(~/.bashrc 中添加):
    #设置ssh连接时的shell配色方案为 ubuntu 自带
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
    
  • 取消与 windows 共享文件夹时, windows 文件夹的背景色:

      echo "eval \`dircolors $HOME/.dir_colors\`" >> ~/.bashrc
      echo "OTHER_WRITABLE 4;40" > ~/.dir_colors
    
  • 怎样解决Windows10时间快和Ubuntu时间差问题? 提供以下两种方法: (ubuntu 18.04.1 此问题解决, 无需手动修改了)
    1. 在 Ubuntu 中把计算机硬件时间改成系统显示的时间,即禁用 Ubuntu的 UTC:
      • timedatectl set-local-rtc 1 --adjust-system-clock
    2. 修改 Windows 对硬件时间的对待方式,让 Windows 把硬件时间当作UTC.
      • win + r 执行: Reg add HKLM\SYSTEM\CurrentControlSet\Control\TimeZoneInformation /v RealTimeIsUniversal /t REG_DWORD /d 1
  • 与 windows 共享文件夹:
    • ubunru 设置:
      • 虚拟机 -> 设置 -> 选项 -> 共享文件夹
    • 创建文件夹软连接:
      • ln -s /mnt/hgfs/win-Desktop/ /home/th1nk3r/
      • 注意需要使用绝对路径, 否则会出现错误: 符号连接的层数过多;

git 相关

  • 安装 git: sudo apt-get install git
  • 设置
    • git clone https://gitee.com/think3r/git_learn.git
    • 拷贝其中的 .gitconfig.gitignore_global~ 目录下;
    • 根据码云的帮助文档进行新的 git 公钥的添加;
  • 配置 ssh 显示 git 分支 :
function parse_git_branch_and_add_brackets {
    git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\ \[\1\]/'
}
#PS1="\h:\W \u\[\033[0;32m\]\$(parse_git_branch_and_add_brackets) \[\033[0m\]\$ "
PS1="${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\[\033[0;32m\]\$(parse_git_branch_and_add_brackets)\[\033[0m\]\$ "
#也就是在原来的 PS1 后添加:
# \[\033[0;32m\]\$(parse_git_branch_and_add_brackets)\[\033[0m\]\$

autojump

# 0x00
git clone https://github.com/wting/autojump.git #拷贝源码

# 0x01 python2 的安装方法
sudo apt install python #安装 python
cd autojump && ./install.py #进入目录并安装

# 0x01 python3 的安装方法:
sudo apt install python3
python3 install.py
sed -i "s/\#\!\/usr\/bin\/env\ python/\#\!\/usr\/bin\/env\ python3/" ~/.autojump/bin/autojump

# .bashrc 添加脚本支持
# j -a `pwd` 添加常用路径

ssh 备份后恢复:

  • ssh-keygen -t ed25519 -C "xxxxx@xxxxx.com" 生成 ssh 密钥对
  • 公钥 *.pub 添加到被登录的机器 ~/.ssh/authorized_keys 文件中即可
  • 仅需在执行 ssh 的客户端机器上保留对应的 ~/.ssh/*rsa 文件即可, 无需保留 *.pub 公钥
    • 保留 *.pub 公钥可避免二次重新生成配置
cp -r .ssh ~/
# fix: 权限相关
chmod 700 ~/.ssh
chmod 600 ~/.ssh/config
chmod 644 ~/.ssh/*.pub
chmod 600 ~/.ssh/*rsa

解决 python pip install慢的方法

# file: ~/.pip/pip.conf
# pip 源: 清华;  (解决pip install慢的方法)[https://blog.csdn.net/yang5915/article/details/83175804]
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple

ubuntu 系统备份

  • 分区与安装挂在目录的选择;
  • 一些相关设置的操作步骤;
  • 更新文件与脚本的备份与使用;
  • ubuntu 常用软件&设置的安装脚本
  • 先使用虚拟机设置 ubuntu 环境. 之后在进行整机的安装.
  • 学习使用 VIM, 同时 vscode 也安装 vimvi
  • cmder 配置与备份
    • alias 设置: C:\Program Files My\cmder\vendor\git-for-windows\etc