ubuntu开机默认进入命令行模式/用户图形界面

开机默认进入命令行模式

输入命令:

sudo systemctl set-default multi-user.target 

重启:

reboot

要进入图形界面,只需要输入命令startx

从图形界面切换回命令行:ctrl+alt+F7

开机默认进入图形用户界面

输入命令:

sudo systemctl set-default graphical.target 

重启:

reboot

要进入命令行模式:ctrl+alt+F2

从命令行切换到图形界面:ctrl+alt+F7

配置vnc

  1. 配置源
cat >> /etc/apt/sources.list <<EOF
deb http://archive.ubuntu.com/ubuntu/ bionic universe
EOF

# 更新下源
apt update
  1. 安装Ubuntu-desktop
sudo apt-get install --no-install-recommends ubuntu-desktop gnome-panel gnome-settings-daemon metacity nautilus gnome-terminal gnome-core
  1. 安装vnc4server
apt-get install vnc4server
  1. 配置xstartup
cat > /root/.vnc/xstartup <<EOF
#!/bin/sh
# Uncomment the following two lines for normal desktop:
unset SESSION_MANAGER
#exec /etc/X11/xinit/xinitrc
gnome-session --session=gnome-classic &

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
#x-terminal-emulator -geometry 1280x1024+10+10 -ls -title "$VNCDESKTOP Desktop" &
#x-window-manager &

EOF

  1. 添加alias,vim ~/.bashrc
cat >> ~/.bashrc <<EOF
alias vkill='vncserver -kill :1'
alias vnc2='vncserver :1 -localhost no'
alias vnc='vncserver :1 -geometry 1920x1080 -localhost no'
EOF

# -localhost no: 开启远程连接

参考链接

  1. https://blog.csdn.net/weixin_39278265/article/details/104273465
  2. https://blog.csdn.net/qq_43381820/article/details/108007815

apt 报错

示例1

cd /var/lib/dpkg
sudo mv info info.bak
sudo mkdir info

ubuntu 22.04 配置静态IP地址

sudo vim /etc/netplan/01-netcfg.yaml

# 修改为以下内容
network:
version: 2
renderer: NetworkManager
ethernets:
ens33:
dhcp4: no
dhcp6: no
addresses:
- 192.168.1.100/24
gateway4: 192.168.1.1
nameservers:
addresses:
- 192.168.1.1

# 重启网络
sudo netplan apply

ubuntu 配置 sudoers

sudo vim /etc/sudoers

# 增加用户的免密 sudo
# 在 %sudo ALL=(ALL:ALL) ALL 下面添加
<username> ALL=(ALL) NOPASSWD:ALL

ubuntu 配置 ssh

sudo apt-get install openssh-server
sudo systemctl enable ssh
sudo systemctl start ssh

ubuntu 配置命令行补全

sudo apt-get install bash-completion
source /etc/bash_completion

# 编辑/etc/bash.bashrc,在最后加入如下代码
if [ -f /etc/bash_completion ]; then
/etc/bash_completion
fi

ubuntu 配置root远程登陆

sudo passwd root
sudo vim /etc/ssh/sshd_config


# 修改如下两行
PermitRootLogin yes # 允许root远程登录
PermitEmptyPasswords no # 不允许空密码登录

# 重启ssh服务
sudo systemctl restart sshd

ubuntu arm 下载地址

https://ubuntu.com/download/server/arm

ubuntu 配置历史命令

vim /etc/profile.d/history.sh

# 添加如下内容
USER_IP=`who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'` #此处的值需要用反撇号取其执行结果
HISTFILESIZE=3000
HISTSIZE=3000
HISTTIMEFORMAT="%F %T ${USER_IP} `whoami` " #此处whoami需要用反撇号取其执行结果
export HISTTIMEFORMAT

# 使配置生效
source /etc/profile