怎样使用Ubuntu

2018年8月13日 | 分类: 【技术】

【介绍】

Ubuntu 是一个以桌面应用为主的开源 GNU/Linux 操作系统。
Ubuntu 基于 Debian GNU/Linux,支持x86、amd64(即x64)和ppc架构,由全球化的专业开发团队(Canonical Ltd)打造的。
Ubuntu 基于 Debian 发行版和 GNOME 桌面环境,而从11.04版起,Ubuntu 发行版放弃了 Gnome 桌面环境,改为 Unity 。

【工具】

build-essential:

sudo apt-get install build-essential -y

参考:https://tecadmin.net/install-development-tools-on-ubuntu/

libtool等:

sudo apt-get install make libtool libtool-bin m4 autoconf automake libtool git aptitude htop dos2unix zip unzip -y

【更新】

sudo apt-get update -y && sudo apt-get upgrade -y && sudo apt-get dist-upgrade -y

或者:

sudo aptitude update -y && sudo aptitude upgrade -y && sudo aptitude dist-upgrade -y

参考:https://ubuntuforums.org/showthread.php?t=1222909

【端口】

参考:https://www.jianshu.com/p/95e5cbd37070

安装:

sudo apt-get install iptables

开启:

iptables -I INPUT -p tcp --dport 端口号 -j ACCEPT

查验:

sudo netstat -tlpn | grep 端口号

如果需要部署网站,需要在Ubuntu系统里开启 80 / 443 两个端口。

iptables -I INPUT -p tcp --dport 80 -j ACCEPT
iptables -I INPUT -p tcp --dport 443 -j ACCEPT

【排错】

问题:更新系统时出现 The following packages have been kept back

新开了一个 Ubuntu 22.04 系统,升级系统时出现:

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Calculating upgrade... Done
The following packages have been kept back:
  libnss-systemd libpam-systemd libsystemd0 libudev1 systemd systemd-sysv
  systemd-timesyncd udev
0 upgraded, 0 newly installed, 0 to remove and 8 not upgraded.

参考:https://itsfoss.com/following-packages-have-been-kept-back/

The fix for this error is really simple. All you have to do is to use the apt install command with package or packages in the question

参考:https://www.codenong.com/f-following-packages-have-been-kept-back/

解决方法:对问题中的一个或多个软件包使用apt install命令

sudo apt install libnss-systemd libpam-systemd libsystemd0 libudev1 systemd systemd-sysv systemd-timesyncd udev

参考:https://askoverflow.dev/ubuntu/question/601/the-following-packages-have-been-kept-back-why-and-how-do-i-solve-it/

解决方法:方案是运行 sudo apt-get install 。在大多数情况下,这将为保留的软件包提供成功升级所需的内容。

sudo apt-get install python3-update-manager update-manager-core

问题:WinSCP 以预设密码进行验证 拒绝访问

方法:关闭 WinSCP ,重新登录后,再使用 Putty。

参考:https://blog.csdn.net/weixin_42672685/article/details/123824826

第一次连接Ubuntu,使用 WinSCP 以预设密码进行验证,提示拒绝访问

解决方案:

路径:vim /etc/ssh/sshd_config

PermitEmptyPasswords yes

重启服务

service ssh restart

2.更改密码

3.核对密码再次登录

问题:缺少依赖

缺 libtool 时,报错:

:~/ModSecurity# ./build.sh
./build.sh: 6: ./build.sh: libtoolize: not found
./build.sh: 7: ./build.sh: autoreconf: not found
./build.sh: 8: ./build.sh: autoheader: not found
./build.sh: 9: ./build.sh: automake: not found
./build.sh: 10: ./build.sh: autoconf: not found

缺 m4 时,报错:

~/ModSecurity# ./build.sh
libtoolize:   error: One of these is required:
libtoolize:                 gm4 gnum4 m4
libtoolize:   error: Please install GNU M4, or 'export M4=/path/to/gnu/m4'.

参考:https://www.howtoinstall.co/en/ubuntu/trusty/m4

缺 autoconf automake 时,报错:

~/ModSecurity# ./build.sh
...
./build.sh: 7: ./build.sh: autoreconf: not found
./build.sh: 8: ./build.sh: autoheader: not found
./build.sh: 9: ./build.sh: automake: not found
./build.sh: 10: ./build.sh: autoconf: not found

参考:https://blog.csdn.net/x356982611/article/details/70856470

sysv-rc-conf:

参考:https://blog.csdn.net/weixin_42380024/article/details/80614290
参考:https://stackoverflow.com/questions/20680050/how-do-i-install-chkconfig-on-ubuntu

ubuntu中chkconfig已经被sysv-rc-conf替代,具体如下操作如下:

chkconfig: command not found

sysv-rc-conf命令:

sudo apt-get install sysv-rc-conf
sysv-rc-conf keepalived on

报错:

Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package sysv-rc-conf

参考:https://askubuntu.com/questions/378558/unable-to-locate-package-while-trying-to-install-packages-with-apt/481355
参考:https://www.cnblogs.com/sunyl1982/p/11864241.html

在软件源列表末尾添加如下内容:/etc/apt/sources.list

deb http://archive.ubuntu.com/ubuntu/ trusty main universe restricted multiverse

更新apt-get:

sudo apt-get update

安装sysv-rc-conf:

sudo apt-get install sysv-rc-conf -y

参考:https://blog.csdn.net/u013554213/article/details/86584705

systemctl:

ubuntu自从15.04版本以后都使用了systemd。Systemctl是一个systemd工具,主要负责控制systemd系统和服务管理器。

参考:https://blog.csdn.net/philosophyatmath/article/details/88863136
参考:https://stackoverflow.com/questions/20680050/how-do-i-install-chkconfig-on-ubuntu

foobar表示伪变量。

打开服务:

systemctl start foobar

关闭服务:

systemctl stop foobar

重启服务:

systemctl restart foobar

不中断正常功能下重新加载服务:

systemctl reload foobar

设置服务的开机自启动:

systemctl enable foobar

关闭服务的开机自启动:

systemctl disable foobar

查看某个服务的状态:

systemctl status foobar

查看已启动的服务列表:

systemctl list-unit-files|grep enabled

查看活跃的单元:

systemctl list-units

查看启动失败的服务列表:

systemctl --failed

【远程桌面:xfce(推荐)】

https://www.codenong.com/f-install-xfce-desktop-xubuntu/

sudo apt install xrdp
sudo apt install xfce4

开启端口:

firewall-cmd --zone=public --add-port=3389/tcp --permanent
firewall-cmd --zone=public --add-port=22/tcp --permanent
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --zone=public --add-port=443/tcp --permanent

重新加载:

service firewalld start
service firewalld reload
firewall-cmd --zone=public --list-ports

【远程桌面:lxde】

参考:https://www.jianshu.com/p/4befb190c94b
参考:https://www.jianshu.com/p/daba3fd81786

sudo apt-get install lxde
sudo apt-get install xrdp

打开 Windows 附件自带的远程桌面连接:

参考:https://jingyan.baidu.com/article/cbcede07ce04ee02f40b4d08.html

1. 按 Windows键 + R ,在运行中输入 mstsc
2. 在远程桌面登录框中输入 IP 地址和 Ubuntu 系统的用户名,点击连接,输入密码。

如果无法连结远程桌面:

方案1:关闭防火墙

ufw disable

方案2:配置安全规则

因为没有配置安全规则。添加入出口端口后就行了。

参考:https://blog.csdn.net/blank_tt/article/details/90759891

安全组》配置规则》添加安全组规则

规则方向:入方向
授权策略:允许
协议类型:自定义TCP
端口范围:3389
授权对象:0.0.0.0

之后,在桌面连接中输入凭据即可。