创建用户
# 创建用户并在 home 文件夹下创建用户 work 目录
useradd -m work
# 修改密码
passwd work
设置用户免密登录
# 在本地将 ssh 公钥上传至服务器
ssh-copy-id -i ~/.ssh/id_rsa.pub work@ip
设置用户 sudo 免密
登录 root
用户,执行 visudo
,找到 root ALL=(ALL) ALL
,在下方添加 work ALL=(ALL) NOPASSWD:ALL
,示例如下:
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
work ALL=(ALL) NOPASSWD:ALL
禁止 root 登录
vi /etc/ssh/sshd_config
# 找到 PermitRootLogin 将 yes 修改为 no
PermitRootLogin no
# 保存后重启 ssh 服务
service sshd restart
禁用密码登录
vi /etc/ssh/sshd_config
# 找到 PubkeyAuthentication 放开注释
PubkeyAuthentication yes
# 找到 PasswordAuthentication 修改为 no
PasswordAuthentication no
# 保存后重启 ssh 服务
service sshd restart
Shell 简易配置
- 自动补全忽略大小写
在用户目录下创建.inputrc
文件,添加set completion-ignore-case on
,保存后使用source
指令或重新登录终端后生效。
VIM 配置
vim
主题
mkdir -p ~/.vim/colors
cd ~/.vim/colors
wget https://raw.githubusercontent.com/gosukiwi/vim-atom-dark/master/colors/atom-dark.vim
wget https://raw.githubusercontent.com/gosukiwi/vim-atom-dark/master/colors/atom-dark-256.vim
.vimrc
配置
set nocompatible " Make vim behave more useful way
"--------------- Themes and color ---------------
set t_CO=256 " Number of colors in terminal
colorscheme atom-dark-256 " My Vim TUI color scheme
syntax on " Enable syntax highlighting
"
""--------------- UI tweaks ---------------
set guifont=Fira_Code:h18 " Monospaced font with programming ligatures
set linespace=16
set number " Show line numbers
set cursorline " Highlight current line
filetype indent on " Load filetype-specific indent files
set noerrorbells " Disable bell for errors that display messages
set vb t_vb= " Disable bell for errors that do not display messages
set guioptions-=l " Hide left scroll bar
set guioptions-=L " Hide left scroll bar in splitted window
set guioptions-=r " Hide right hand scroll bar
set guioptions-=R " Hide right hand scroll bar in splitted window
set showmatch " Highlight matching {[()]} automatically
set wildmenu " Visualize autocomplete menu for command
set scrolljump=5 " Lines to scroll when cursor leaves screen
set scrolloff=3 " Minium lines to keep above and below the cursor
set laststatus=2 " Always display status line
set ruler " Display the line and column of the cursor in status bar
hi CursorLine cterm=NONE ctermbg=darkred ctermfg=white
"--------------- Indentation ---------------
"set tabstop=4 " Number of spaces per tab
"set shiftwidth=4 " Indent 4 columns for << and >> operations
"set expandtab " Replace tab with space
"set autoindent " Indent at the same level of the previous
"line
"
""--------------- Searching ---------------
set hlsearch " Highlight search result
set incsearch " Search as characters in real time
root
用户特别配置
在.bashrc
文件增加以下内容
alias vi='vim'
设置客户端连接超时断开
vi /etc/ssh/sshd_config
# 找到 ClientAliveInterval 修改为 60,该值代表客户端每隔多少秒发送一次响应到服务器(s)
ClientAliveInterval 60
# 找到 ClientAliveCountMax 修改为 120,该值代表服务器发出请求后客户端没有响应的次数上限
ClientAliveCountMax 120
# 保存后重启 ssh 服务
service sshd restart
JDK 安装
# 下载 JDK tar 包
wget https://download.oracle.com/otn/java/jdk/8u261-b12/a4634525489241b9a9e1aa73d9e118e6/jdk-8u261-linux-x64.tar.gz
# 解压下载文件
tar -zxvf jdk-8u261-linux-x64.tar.gz
cp -r jdk1.8.0_261 /usr/local/src/
- 配置环境变量
vi /etc/profile
# 添加以下内容
# --------- Java ----------
export JAVA_HOME=/usr/local/src/jdk1.8.0_261
export CLASSPATH=.:$JAVA_HOME/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
# 保存并退出编辑模式
# 刷新当前连接的环境变量
source /etc/profile
# 查看 JDK 安装版本
java -version
# 成功