Skip to content

ubuntu初始化

本人常用的linux配置,使用的是阿里云的ubuntu20.04系统

[TOC]

1、源与基本软件安装

阿里云本身就是国内镜像,不需要替换直接更新

bash
#更新源
apt update
#更新软件
apt upgrade

接着安装基本软件

bash
apt install git nodejs zsh neovim vsftpd nginx yarn

2、用户管理

bash
#修改阿里云自带用户的用户名(这里就不修改用户组了,仍然使用admin用户组)
usermod -l sqm admin
#修改用户密码
passwd sqm
#修改家目录admin为sqm
mv admin sqm

3、zsh及oh-my-zsh配置

bash
#设置当前用户shell为zsh
sudo usermod -s /usr/bin/zsh $(whoami)
#安装oh-my-zsh
#gitee官方镜像网址	https://gitee.com/mirrors/oh-my-zsh
git clone https://gitee.com/mirrors/oh-my-zsh.git
#根据oh-my-zsh文档运行命令安装
sh ./oh-my-zsh/tools/install.sh

配置oh-my-zsh使用powerlevel10k主题,这里使用的是gitee某用户提供的镜像命令

bash
git clone --depth=1 https://gitee.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k

修改~/.zshrc配置文件更换主题为ZSH_THEME="powerlevel10k/powerlevel10k"

vim ~/.zshrc

再次切换进入zsh会提示进行配置,这里按照提示一步步的来就好,如果选错了也是可以使用p10k configure命令重新配置的

关于其他用户的zsh配置

现在/etc/passwd中修改要配置用户的shell,然后将根目录的.zshrc文件和.oh-my-zsh文件夹拷贝到 /home/要配置用户 的目录下,并从拷贝的.zshrc中更改export ZSH="$HOME/.oh-my-zsh"

关于zsh插件安装

个人推荐如下,zsh-autosuggestions 与 zsh-syntax-highlighting 可以使用gitee镜像的git地址下载

shell
plugins=(
  git autojump zsh-autosuggestions extract web-search zsh-syntax-highlighting 
)

4、vim与nvim的配置

使用vimplus安装管理vim,下面贴出gitee地址,但是该项目引用较多github项目,可以仅用作装YCM补全

https://gitee.com/chxuan/vimplus

nvim可以使用coc.nvim补全,这里先安装vim-plug插件管理,下面是官网给出的nvim安装方式

bash
sh -c 'curl -fLo "${XDG_DATA_HOME:-$HOME/.local/share}"/nvim/site/autoload/plug.vim --create-dirs \
quote>        https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'

nvim的vim-plug配置文件在~/.config/nvim/init.vim,没有需要新建。

接着在~/.config/nvim/init.vim文件中定义插件coc.nvim,这里用的是gitee的镜像

vim
call plug#begin('~/.vim/plugged')
	Plug 'https://gitee.com/zgpio/coc.nvim.git'
call plug#end()

接着根据coc.nvim官方文档,这里安装yarn包管理器,并且更改yarn源为国内源

最后进入nvim,执行:PlugInstall安装插件

关于多用户同步方案

由于linux是多用户系统,需要对每个用户的vim、nvim进行配置,解决方法有将配置文件放在同步文件夹中,或者将配置文件git到网上,切换用户时clone即可。这里未进行尝试

5、配置ftp、sftp、vnc

ftp与sftp开启

配置阿里云防火墙,开启21,22,20端口

配置之前安装的vsftpd的配置文件 /etc/vsftpd.conf(网上有说是/etc/vsftpd/vsftpd.conf,个人实践时发现并未此文件,且修改/etc/vsftpd.conf才生效,可能是vsftpd版本原因)

参考配置(官改,改动处有中文注释,复制粘贴需要注意):

bash
# Example config file /etc/vsftpd.conf
#
# The default compiled in settings are fairly paranoid. This sample file
# loosens things up a bit, to make the ftp daemon more usable.
# Please see vsftpd.conf.5 for all compiled in defaults.
#
# READ THIS: This example file is NOT an exhaustive list of vsftpd options.
# Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's
# capabilities.
#
#
# Run standalone?  vsftpd can run either from an inetd or as a standalone
# daemon started from an initscript.
listen=NO
#
# This directive enables listening on IPv6 sockets. By default, listening
# on the IPv6 "any" address (::) will accept connections from both IPv6
# and IPv4 clients. It is not necessary to listen on *both* IPv4 and IPv6
# sockets. If you want that (perhaps because you want to listen on specific
# addresses) then you must run two copies of vsftpd with two configuration
# files.
listen_ipv6=YES
#
# 是否运行匿名用户登录,YES为允许
anonymous_enable=NO
#
# Uncomment this to allow local users to log in.
local_enable=YES
#
# 为ftp开启写的权限,YES开启
write_enable=YES
#
# Default umask for local users is 077. You may wish to change this to 022,
# if your users expect that (022 is used by most other ftpd's)
#local_umask=022
#
# Uncomment this to allow the anonymous FTP user to upload files. This only
# has an effect if the above global write enable is activated. Also, you will
# obviously need to create a directory writable by the FTP user.
#anon_upload_enable=YES
#
# Uncomment this if you want the anonymous FTP user to be able to create
# new directories.
#anon_mkdir_write_enable=YES
#
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES
#
# If enabled, vsftpd will display directory listings with the time
# in  your  local  time  zone.  The default is to display GMT. The
# times returned by the MDTM FTP command are also affected by this
# option.
use_localtime=YES
#
# Activate logging of uploads/downloads.
xferlog_enable=YES
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES
#
# If you want, you can arrange for uploaded anonymous files to be owned by
# a different user. Note! Using "root" for uploaded files is not
# recommended!
#chown_uploads=YES
#chown_username=whoever
#
# You may override where the log file goes if you like. The default is shown
# below.
#xferlog_file=/var/log/vsftpd.log
#
# If you want, you can have your log file in standard ftpd xferlog format.
# Note that the default log file location is /var/log/xferlog in this case.
#xferlog_std_format=YES
#
# You may change the default value for timing out an idle session.
#idle_session_timeout=600
#
# You may change the default value for timing out a data connection.
#data_connection_timeout=120
#
# It is recommended that you define on your system a unique user which the
# ftp server can use as a totally isolated and unprivileged user.
#nopriv_user=ftpsecure
#
# Enable this and the server will recognise asynchronous ABOR requests. Not
# recommended for security (the code is non-trivial). Not enabling it,
# however, may confuse older FTP clients.
#async_abor_enable=YES
#
# By default the server will pretend to allow ASCII mode but in fact ignore
# the request. Turn on the below options to have the server actually do ASCII
# mangling on files when in ASCII mode.
# Beware that on some FTP servers, ASCII support allows a denial of service
# attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd
# predicted this attack and has always been safe, reporting the size of the
# raw file.
# ASCII mangling is a horrible feature of the protocol.
#ascii_upload_enable=YES
#ascii_download_enable=YES
#
# You may fully customise the login banner string:
#ftpd_banner=Welcome to blah FTP service.
#
# You may specify a file of disallowed anonymous e-mail addresses. Apparently
# useful for combatting certain DoS attacks.
#deny_email_enable=YES
# (default follows)
#banned_email_file=/etc/vsftpd.banned_emails
#
# You may restrict local users to their home directories.  See the FAQ for
# the possible risks in this before using chroot_local_user or
# chroot_list_enable below.
#chroot_local_user=YES
#
# You may specify an explicit list of local users to chroot() to their home
# directory. If chroot_local_user is YES, then this list becomes a list of
# users to NOT chroot().
# (Warning! chroot'ing can be very dangerous. If using chroot, make sure that
# the user does not have write access to the top level directory within the
# chroot)
#用户限制在自身家目录,yes为开启,暂不开启,会导致ftp登录失败,需要按照local_root进行配置
#chroot_local_user=YES
#chroot_list_enable=NO
# (default follows)
#chroot_list_file=/etc/vsftpd.chroot_list
# 用户登录路径,local_root 针对系统用户,这里chmod 755 目标文>
# 并在下面建立子文件夹 chown 子用户 子文件夹 转让权限
# 需要时进行配置并注释掉下面的代码及chroot_local_user
#local_root=/var/ftp/
#
# You may activate the "-R" option to the builtin ls. This is disabled by
# default to avoid remote users being able to cause excessive I/O on large
# sites. However, some broken FTP clients such as "ncftp" and "mirror" assume
# the presence of the "-R" option, so there is a strong case for enabling it.
#ls_recurse_enable=YES
#
# Customization
#
# Some of vsftpd's settings don't fit the filesystem layout by
# default.
#
# This option should be the name of a directory which is empty.  Also, the
# directory should not be writable by the ftp user. This directory is used
# as a secure chroot() jail at times vsftpd does not require filesystem
# access.
secure_chroot_dir=/var/run/vsftpd/empty
#
# This string is the name of the PAM service vsftpd will use.
pam_service_name=vsftpd
#
# This option specifies the location of the RSA certificate to use for SSL
# encrypted connections.
rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
ssl_enable=NO

#
# Uncomment this to indicate that vsftpd use a utf8 filesystem.
#utf8_filesystem=YES

配置好后使用 service vsftpd start 启动 ftp 服务,

sftp在该系统中是默认启动的(openssh-server),修改密码即可访问

vnc的配置

先安装Xfce桌面环境

bash
sudo apt install xfce4 xfce4-goodies

安装vnc服务器

bash
sudo apt install tightvncserver

启动vnc

bash
sudo vncserver

停止并配置vnc

bash
#停止端口号5901的服务,vnc默认从5900开始排端口号,也有其他方式停止
sudo vncserver -kill :1
#备份原文件
mv ~/.vnc/xstartup ~/.vnc/xstartup.bak
#创建新文件
touch ~/.vnc/xstartup
#进入编辑
vim ~/.vnc/xstartup

命令如图

bash
#!/bin/bash
xrdb $HOME/.Xresources
startxfce4 &

确保成功访问还要添加权限

bash
chmod +x ~/.vnc/xstartup

最后重启vnc服务器即可

6、回收站设置

安装回收站工具

bash
sudo apt install trash-cli

可以在对应shell中设置别名覆盖rm,防止使用该命令

总结

配置不易,要少用root勤备份

鄂ICP备19018246号-1