Linux基本配置

Linux使用

换源

镜像源参考列表

我使用的Ubuntu18.04,用的是阿里源

deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

步骤

1.备份原始源文件source.list

桌面打开终端,执行命令:sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

2.修改源文件source.list

  • 执行命令:sudo vim /etc/apt/source.list打开文件进行编辑;

  • 复制镜像到文件中,然后保存

3.更新源

桌面终端执行命令:sudo apt update更新软件列表,换源完成。

$ cd /etc/apt/
$ cp sources.list sources.list.bak ## 备份系统自带的source列表
## 选择合适的镜像源,如阿里云的镜像 http://mirrors.aliyun.com/ubuntu
$ sed -i 's/^\(deb\|deb-src\) \([^ ]*\) \(.*\)/\1 http:\/\/mirrors.aliyun.com\/ubuntu \3/' sources.list
## 更新apt
$ apt-get update

发现大神换源的方法都和我们不一样。

修改终端

这一步可以参考这篇博客

终端是我们在linux中使用最多的一个东西,因此,一个功能强大,界面美观的终端是十分有必要的。

我个人十分喜欢zsh,功能强大,自定义程度高。

配置zsh主题

1.安装 zsh 软件包和 git

sudo apt -y install zsh git

2. 克隆 oh-my-zsh

git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh

3. 复制 .zshrc,修改命令提示符样式

cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc

4.修改主题

#查看可以修改的主题
ls ~/.oh-my-zsh/themes
vim .zshrc
#找到ZSH_THEME并修改为如下,eg修改为agnoster
ZSH_THEME="agnoster"

4. 修改 shell 类型

chsh -s /bin/zsh

配置高亮和补全

zsh-autosuggestions

安装zsh-autosuggestions

git clone git://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions

编辑~/.zshrc文件

vim ~/.zshrc
## 修改内容
plugins=(git zsh-autosuggestions)
##刷新
source ./zshrc

zsh-syntax-highlighting

下载zsh-syntax-highlighting

git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $ZSH_CUSTOM/plugins/zsh-syntax-highlighting

激活插件

vim ~/.zshrc
plugins=( [plugins...] zsh-syntax-highlighting)
source ~/.zshrc

插件

官方插件:https://github.com/ohmyzsh/ohmyzsh/wiki/Plugins-Overview

z

#提供一个 z 命令,在常用目录之间跳转。类似 autojump,但是不需要额外安装软件。
z 目录

extract

#功能强大的解压插件,所有类型的文件解压一个命令x全搞定,再也不需要去记tar后面到底是哪几个参数了。
x xx.zip
x xx.tar.gz
x xx.rar
x xx.gz

配置ssh登录

服务端配置

sudo vim /etc/ssh/sshd_config

#修改Port为其它端口

#重启ssh服务
service ssh restart
#或者  systemctl restart sshd.service

客户端配置

免密登录

ssh-keygen -t rsa
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
scp -P 2256 ~/.ssh/authorized_keys root@192.168.0.115:/root/.ssh/

#服务端更改权限
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

windows可以配置C:\Users\用户名\.ssh\config

Host vps    
    HostName x.x.x.x
    User name
    Port 2256
    IdentityFile C:\Users\用户名\.ssh\id_rsa

然后可以快速登录和传递文件

ssh vps
scp aa.txt vps:~/

安装常用命令

tldr

sudo apt-get update
sudo apt-get install tldr
mkdir -p ~/.tldr/tldr
sudo git clone https://codechina.csdn.net/mirrors/tldr-pages/tldr.git ~/.tldr/tldr

配置环境

修改主机名

vim /etc/hostname

python3和pip3

linux一般是自代python2和pip2的

#安装python3
sudo apt search python3
sudo apt install python3.8-dbg
#安装pip3
sudo apt-get install python3-pip
sudo pip3 install --upgrade pip

安装docker

sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common
    
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"
   
   
sudo apt-get update

sudo apt-get install docker-ce

sudo docker run hello-world

删除docker

sudo apt-get remove docker  
sudo apt-get remove --auto-remove docker
sudo apt-get autoremove docker-ce-*

# 查询相关软件包
dpkg -l | grep docker
# 删除这个包
sudo apt remove --purge dock.io
#删除docker的相关配置&目录
sudo rm -rf /etc/systemd/system/docker.service.d
sudo rm -rf /var/lib/docker

#确定docker卸载完毕
docker --version

安装常用程序

#用于从服务器上上传、下载文件
sudo apt install lrzsz
sudo apt install tree
#安装mysql服务
sudo apt-get install mysql-server
#配置初始化信息
sudo mysql_secure_installation
#配置远程访问
sudo mysql -uroot -p
use mysql;
select User,authentication_string,Host from user;
#设置权限与密码
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root';  
#刷新cache中配置
flush privileges; 
posted @ 2020-05-07 18:19  tomyyyyy  阅读(262)  评论(0编辑  收藏  举报