Table of contents
-
- 1. Introduction
- 2. Frequently asked questions
-
- 1. Ubuntu does not display the wired connection icon and cannot save the network ip settings
- 2. Ubuntu cannot log in as root
- 3. The git command cannot be automatically completed
- 4. The root user cannot complete the git command, but ordinary users can
- 5. How to set the root user to log in automatically
- 6. ssh login windows settings
- 7. sudo does not need to enter a password
- 8. Set su to not require a password
- 9. Set DNS
- 10. ssh cannot remotely log in to the Ubuntu system as the root user
- 11. After setting the static ip through graphics or scripts, restarting will automatically add a dhcp ip
- 12. The process of building tftp server in linux system
- 13. Limit sudo's scope of execution root permissions
1. Introduction
This article mainly summarizes the common system problems of ubuntu, as follows:
1. ubuntu does not display the wired connection icon, and cannot save network ip settings;
2. ubuntu cannot log in as root;
3. git commands cannot be automatically completed;
4. root users cannot git commands
5. How to set the root user to log in automatically 6.
ssh login windows setting
7. Sudo does not need to enter a password
9. Set DNS
10. Ssh cannot remotely log in to the Ubuntu system as the root user
11. Set through graphics or scripts After the static ip is restarted, a dhcp ip will be added automatically. 12.
The process of building a tftp server in the linux system.
2. Frequently asked questions
Note: ubuntu installs no vim command by default, you can use gedit instead.
1. Ubuntu does not display the wired connection icon and cannot save the network ip settings
method one:
/etc/NetworkManager/NetworkManager.conf中managed=false改为managed=true
[main]
plugins=ifupdown,keyfile
[ifupdown]
managed=true
[device]
wifi.scan-rand-mac-address=no
/usr/lib/NetworkManager/conf.d/10-globally-managed-devices.conf新增except:type:ethernet
[keyfile]
unmanaged-devices=*,except:type:ethernet,except:type:wifi,except:type:gsm,except:type:cdma
Method Two:
sudo service network-manager stop
sudo rm /var/lib/NetworkManager/NetworkManager.state
sudo service network-manager start
sudo gedit /etc/NetworkManager/nm-system-settings.conf
false ----改成---> true
sudo service network-manager restart
(1) Ubuntu Server modify IP address
sudo vim /etc/network/interfaces
Add the following statement:
auto eth0
iface eth0 inet static
address xxx.xxx.xxx.xxx #IP地址
netmask xxx.xxx.xxx.xxx #子网掩码
gateway xxx.xxx.xxx.xxx #网关
(2) Ubuntu Server modify DNS
sudo vim /etc/resolv.conf
Change it to the following:
search localdomain #如果本Server为DNS服务器,可以加上这一句,如果不是,可以不加
nameserver 172.16.3.4 #希望修改成的DNS
nameserver 172.16.3.3 #希望修改成的DNS
2. Ubuntu cannot log in as root
1. Log in as a normal user, open the terminal to execute the command, use su root or sudo -i to switch to the root user (required)
su root
Follow the prompts to enter the password to switch users.
If you forget the password of the root account, run the following command to reset it before switching.
sudo passwd root
2. Enter the following command in the terminal to open the file
vim /etc/pam.d/gdm-autologin
Add # before the third line in the opened file, comment out the statement "auth required pam_succeed_if.so user != root quiet_success"
3, save and exit, and continue to execute in the terminal
vim /etc/pam.d/gdm-password
Add # to the third line of the opened file and comment out the statement "auth required pam_succeed_if.so user != root quiet_success"
4, save and exit. Continue to execute in the terminal
vim /root/.profile
Change "mesg n 2> /dev/null || true" in the opened file to
tty -s&&mesg n 2> /dev/null || true
5. Save and exit.
6. Restart the computer, you can log in as root user.
3. The git command cannot be automatically completed
apt install bash-completion -y //重启终端
4. The root user cannot complete the git command, but ordinary users can
1. Open the following file with vim
vim /root/.bashrc
2. Find the last three lines, remove the # in front of the three commented out lines, and then log in to the account again.
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
. /etc/bash_completion
fi
5. How to set the root user to log in automatically
1. Firstly, according to the second point, you must first set the root user to log in;
2.
Add the following content to vim /etc/gdm3/custom.conf:
[daemon]
AutomaticLoginEnable=true
AutomaticLogin=root
6. ssh login windows settings
Windows installation ssh service steps:
1. Open windows10, add Openssh server program in Settings/Applications/Applications and Functions/Optional Functions/Add Functions, download
2. In win+S, service, open the local service interface, find OpenSSH SSH Server, the startup mode is changed to automatic
3. Open the firewall/advanced settings/new inbound rules/open port 22 (SSH default)
7. sudo does not need to enter a password
Set the test user, pay attention to add the content to the end, it may be overwritten by the group set by the group and it will not take effect
vim /etc/sudoers
#%test ALL=(ALL) NOPASSWD: ALL
test ALL=(ALL) NOPASSWD: ALL
8. Set su to not require a password
If you do not need to enter a password for the su command for a certain user, you need to modify the following:
1) Switch to root authority;
2) Create a group as a wheel group, and the command is groupadd wheel;
3) Add the user to the wheel group, and the command is usermod -G wheel test;
4) Modify the su configuration file /etc/pam.d/su, add the following items:
auth required pam_wheel.so group=wheel
auth sufficient pam_test.so trust use_uid
9. Set DNS
Note that normally we change /etc/resolv.conf to take effect temporarily, and we need to change it if we want to save it permanently:
vim /etc/resolvconf/resolvconf.base
nameserver 192.168.2.40 //DNS
//重启服务
resolvconf -u
systemctl restart resolvconf.service
//也可以在resolvconf.service中的脚本中加入
vim /lib/systemd/systemd-resolved //将DNS注释去掉然后设置DNS值
DNS=8.8.8.8
10. ssh cannot remotely log in to the Ubuntu system as the root user
vim /etc/ssh/sshd_config
PermitRootLogin prohibit-password
StrictModes yes
Change to:
11. After setting the static ip through graphics or scripts, restarting will automatically add a dhcp ip
1. Turn off dhcp to automatically generate ip
vim /etc/netplan/00-installer-config.yaml // dhcp4: 内容改为false
network:
ethernets:
enp0s31f6:
dhcp4: false
version: 2
2. View the dhch automatically generated configuration file directory
/etc/NetworkManager/system-connections/xxx
12. The process of building tftp server in linux system
1. Install dependent packages
sudo apt-get install tftp-hpa tftpd-hpa
sudo apt-get install xinetd
2. Configure /etc/xinetd.conf
vi /etc/xinetd.conf
# Simple configuration file for xinetd
#
#Some defaults, and include /etc/xinetd.d/
defaults
{ #Please note that you need a log_type line to be able to use log_on_success #and log_on_failure. The default is the following: #log_type = SYSLOG daemon info } includedir /etc/xinetd.d Check whether there is xinetd.conf Check whether the content is consistent, if not create one, and enter the following content
3. Configure /etc/default/tftpd-hpa
sudo vim /etc/default/tftpd-hpa
set shared directory TFTP_DIRECTORY="/srv/tftp"
Create folder mkdir /srv/tftp
4. Set permissions chmod 777 /srv/tftp -R
5. Restart tftp service sudo service tftpd-hpa start
13. Limit sudo's scope of execution root permissions
Because sometimes ordinary users are required to use some root privileges, which can be restricted by sudo, as follows:
vim /etc/sudoers
//指定可执行和不可执行的命令
test ALL = ALL, !/bin/su ,!/bin/apt-get,!/bin/dpkg,!/bin/chattr //su、apt-get、dpkg、chattr命令无权限执行
//执行会报错:Sorry, user test is not allowed to execute '/usr/sbin/su' as root
//chattr可以限制该文件被普通用户以sudo方式更改
//终端执行以下命令限制文件不可更改,取消限制用参数-i
chattr +i /etc/sudo.conf
chattr +i /etc/sudoers
chattr +i /etc/sudoers.d/
At this time, ordinary users cannot execute restricted commands in sudo mode, and cannot change the configuration
//常见需要限制的命令如下:
test ALL = ALL, !/bin/su ,!/bin/apt-get,!/bin/dpkg,!/bin/apt,!/bin/chattr,!/bin/passwd,!/sbin/visudo,!/sbin/useradd,!/sbin/adduser,!/sbin/userdel,!/sbin/deluser,!/bin/rm,!/bin/rmdir,!/bin/vi,!/bin/vim,!/bin/gedit,!/sbin/poweroff,!/sbin/reboot,!/sbin/init,!/sbin/ifup,!/sbin/ifdown