AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / unix / 问题

问题[ubuntu](unix)

Martin Hope
Sam99
Asked: 2025-04-28 05:30:52 +0800 CST

如何在 Ubuntu 22.04 上使 IP 链接设置持久化

  • 5

我正在尝试在 Ubuntu 22.04 桌面版上持久化某些 IP 链接设置。
以下命令运行正常,但无法持久化:

ip link add mynet-shim link eno1 type macvlan  mode bridge
ip addr add 192.168.1.223/32 dev mynet-shim
ip link set mynet-shim up
ip route add 192.168.1.192/27 dev mynet-shim

我试过使用,nmcli但桥接似乎macvlan不可用。请问您有什么建议或教程可以解释如何操作吗?

ubuntu
  • 1 个回答
  • 53 Views
Martin Hope
Àwwsome
Asked: 2025-04-23 02:34:23 +0800 CST

我已经使用 VMWare 在笔记本电脑上虚拟安装了 Ubuntu。如何在笔记本电脑的其余部分找到 Windows 目录?

  • 5

我使用的是一台运行 Windows 10 的老款笔记本电脑(它预装的是 Win8)。我已经使用 VMware 在笔记本电脑上虚拟安装了 Ubuntu,但想从 Ubuntu 访问笔记本电脑其余部分(Windows 分区中)的文件,尤其是 C: 和 D: 盘上我的文档文件夹中的文件。我该怎么做?如何通过 cd 命令访问这些驱动器/文件夹?

ubuntu
  • 2 个回答
  • 77 Views
Martin Hope
AlanQ
Asked: 2025-04-19 01:53:00 +0800 CST

systemd-journald 平均每小时写入 16MB!

  • 6

操作系统:Ubuntu MATE 24.04.2 LTS

我在顶部面板添加了系统监视器,发现磁盘活动非常多。
起初我以为主要的“罪魁祸首”是jbd2——日志块设备。
但 jbd2(“一种在系统崩溃时保护文件系统免受元数据不一致影响的日志”)应该只会在响应其他写入磁盘的操作时才写入磁盘。
运行后sudo iotop -a,我发现 (*) 写入磁盘的主要对象是systemd-journald:在 3 小时 40 分钟内,它写入了 60MB!

我知道这是二进制数据,但是,如果它是文本,即使每个字符有 4 个字节,那么每 7 小时就会出现一次“战争与和平”!

  • 这是‘正常’的吗?
  • 写什么需要这么多数据?
  • 我应该担心我的 SSD 系统盘吗?
  • 我可以(安全地)减少写入数据的数量(和频率)吗?

(*) 尽管 Firefox 是个怪物

ubuntu
  • 2 个回答
  • 60 Views
Martin Hope
learningtech
Asked: 2025-04-18 04:43:16 +0800 CST

Cgroups 权限在 Ubuntu 22.04.5 上被拒绝,但在 Ubuntu 22.04.03 上可以运行

  • 6

我正在尝试了解 cgroups。我运行了以下两个命令:

root@localhost:~# mkdir /sys/fs/cgroup/container_cpu
root@localhost:~# echo '50000 100000' | sudo tee /sys/fs/cgroup/container_cpu/cpu.max

这在我的虚拟机上的 Ubuntu 22.04.3 上运行良好,但在 linode.com 上的 Ubuntu 22.04.5 上,我收到了错误:

tee: /sys/fs/cgroup/container_cpu/cpu.max: Permission denied

谁能告诉我我做错了什么?

ubuntu
  • 1 个回答
  • 27 Views
Martin Hope
user1887384
Asked: 2025-04-17 15:48:40 +0800 CST

尝试登录 sftp 失败

  • 5

我正在尝试使用 openssh 内置 sftp 设置 sftp 服务器。

Subsystem       sftp    /usr/lib/openssh/sftp-server

并且我按照以下步骤创建了用户(或多或少(使用 ansible),我确实使用 /sbin/nologin 作为 shell,并使用 /dev/null 作为 skel) https://sftpcloud.io/learn/sftp/how-to-setup-sftp-server-on-ubuntu-22-04

但当我尝试连接时

sftp myuser@myip

我收到提示并输入密码,但失败了

client_loop: send disconnect: Broken pipe
Connection closed.  
Connection closed

问题是,现在用户的主目录中充满了垃圾。

$ ls -a
snap/  .cache  .local

我在系统日志中看到很多事情发生,这些事情似乎与以普通用户身份登录有关(我猜)。以下是一些内容

systemd[1]: Created slice user-1003.slice - User Slice of UID 1003.
systemd[1]: Starting [email protected] - User Runtime Directory /run/user/1003...
snapd-desktop-i[4568]: Detected new session 42 at /org/freedesktop/login1/session/_342
systemd[1]: Finished [email protected] - User Runtime Directory /run/user/1003.
systemd[1]: Starting [email protected] - User Manager for UID 1003...
systemd-xdg-autostart-generator[14091]: Exec binary 'start-pulseaudio-x11' does not exist: No such file or directory
systemd-xdg-autostart-generator[14091]: /etc/xdg/autostart/pulseaudio.desktop: not generating unit, executable specified in Exec= does not exist.
systemd[14080]: Queued start job for default target default.target.
systemd[14080]: Created slice app.slice - User Application Slice.
systemd[14080]: Created slice session.slice - User Core Session Slice.
systemd[14080]: Started ubuntu-report.path - Pending report trigger for Ubuntu Report.
systemd[14080]: Started launchpadlib-cache-clean.timer - Clean up old files in the Launchpadlib cache.
systemd[14080]: Starting gpg-agent-ssh.socket - GnuPG cryptographic agent (ssh-agent emulation)...
systemd[1]: Started [email protected] - User Manager for UID 1003.
systemd[1]: Started session-42.scope - Session 42 of User myuser.
systemd[14080]: Starting gnome-initial-setup-copy-worker.service - GNOME Initial Setup Copy Worker...
systemd[14080]: Started pipewire.service - PipeWire Multimedia Service.
systemd[14080]: Started filter-chain.service - PipeWire filter chain daemon.
systemd[14080]: Started snap.snapd-desktop-integration.snapd-desktop-integration.service - Service for snap application snapd-desktop-integration.snapd-desktop-integration.
systemd[14080]: Started wireplumber.service - Multimedia Service Session Manager.
systemd[14080]: Started pipewire-pulse.service - PipeWire PulseAudio.
systemd[14080]: Startup finished in 270ms.
systemd[14080]: Starting dbus.service - D-Bus User Message Bus...
pipewire[14099]: mod.jackdbus-detect: Failed to receive jackdbus reply: org.freedesktop.DBus.Error.ServiceUnknown: The name org.jackaudio.service was not provided by any .service files
wireplumber[14113]: SPA handle 'api.libcamera.enum.manager' could not be loaded; is it installed?
systemd[14080]: snap.snapd-desktop-integration.snapd-desktop-integration.service: Main process exited, code=exited, status=1/FAILURE
systemd[14080]: snap.snapd-desktop-integration.snapd-desktop-integration.service: Failed with result 'exit-code'.

所以我猜登录会触发“其他操作”,如何禁用正在发生的额外操作,只保留 sftp 呢?我确实有其他“普通”用户登录到我尝试设置为 sftp 服务器的服务器,所以我必须以特殊方式处理这些 sftp 用户。但是该怎么做呢?

我使用 Ubuntu 24.04。我的 sshd_config 显示:

UsePAM yes
ubuntu
  • 1 个回答
  • 41 Views
Martin Hope
Alessandro
Asked: 2025-04-05 00:37:12 +0800 CST

Ubuntu Budgie 24.10 - 应用中心错误“无法创建 gx 会话”

  • 5

在 Ubuntu Budgie 24.10 上,打开应用中心工具和其他应用程序(例如桌面安全和固件更新程序)时,页面会显示一个空白页,并显示错误消息:“无法创建 GX 会话”。我怀疑这个问题与 Nvidia 3050 GPU、最新的 Nvidia 驱动程序和 X11 图形系统有关。降级 Nvidia 驱动程序或重新安装有问题的软件等解决方法均无效。我在网上搜索了一下,这似乎是一个已知的 bug。请问您找到解决方案了吗?还是说升级到新发布的 Ubuntu 25 是唯一的选择?

ubuntu
  • 1 个回答
  • 20 Views
Martin Hope
Marco Klein
Asked: 2025-04-01 03:35:31 +0800 CST

Firewalld 忽略针对端口转发的 rich-rule

  • 8

我在设置firewalld与docker和fail2ban完美连接时遇到问题。

首先,我想要实现的是以下流量路由设置:

[PUBLIC] -> 
  [FIREWALLD] -> (
    [143/tcp FORWARD PORT] -----> [DOCKER/143/tcp]
    [ 22/tcp]              -----> [openssh locally running]
  )

失败2ban

我设置了 fail2ban 来监听我的 docker 容器,检查身份验证错误并使用 设置禁令firewall-cmd。到目前为止,这很有效。只要我 3 次身份验证错误,它就会向防火墙发送命令。

端口转发

我还为 docker 设置了端口转发。我明确地设置了它,因为我不想让 docker 破坏我的网络。也许这是我将来不需要的东西,但它是通过StrictForwardPorts=yes配置配置的。https ://firewalld.org/2024/11/strict-forward-ports

目标

目标是每当触发 fail2ban 时,IP都不应再访问端口 143(转发端口),并且(可能)其他端口也不应再访问。但首先,我想逐个端口禁止。

问题

当前的问题是,如果创建了拒绝富规则,它将阻止该 IP 的端口 22,但不会阻止端口 143。

尝试 我还尝试将 IP 放入drop区域,并赋予其优先级-10。同样的错误结果。端口 22 被丢弃,但 143 仍然有效。

我做错了什么?这是我上次尝试的区域配置:

docker (active)
  target: ACCEPT
  ingress-priority: 0
  egress-priority: 0
  icmp-block-inversion: no
  interfaces: br-0aa8d4b5dde7 docker0
  sources: 
  services: 
  ports: 
  protocols: 
  forward: yes
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 
        rule priority="-999" family="ipv4" source address="192.168.178.44" reject

drop (active)
  target: DROP
  ingress-priority: -10
  egress-priority: -10
  icmp-block-inversion: no
  interfaces: 
  sources: 192.168.178.44
  services: 
  ports: 
  protocols: 
  forward: yes
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 

public (default, active)
  target: default
  ingress-priority: 0
  egress-priority: 0
  icmp-block-inversion: no
  interfaces: 
  sources: 
  services: dhcpv6-client ssh
  ports: 
  protocols: 
  forward: yes
  masquerade: no
  forward-ports: 
        port=143:proto=tcp:toport=143:toaddr=172.18.0.2
  source-ports: 
  icmp-blocks: 
  rich rules: 
        rule priority="-999" family="ipv4" source address="192.168.178.44" reject

如图所示:实际上,地址 192.168.178.44 应该完全阻止进入公共区域。但事实并非如此。此外,我还将 IP 添加到了丢弃区。丢弃区优先级似乎正在发挥作用,因为我的 SSH 连接被丢弃而不是被拒绝,但端口 143 仍然可以访问

更新 1:一些调试信息

$ sudo firewall-cmd --get-policies
allow-host-ipv6 docker-forwarding

更新 2:--info-policy=docker-forwarding

docker-forwarding (active)
  priority: -1
  target: ACCEPT
  ingress-zones: ANY
  egress-zones: docker
  services: 
  ports: 
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: `

更新 3:

我想到另一个想法是创建另一个优先级为 -10 的策略,其中包含丰富的规则:

sudo firewall-cmd --permanent --new-policy ban-pre-routing
sudo firewall-cmd --permanent --policy ban-pre-routing --add-ingress-zone ANY
sudo firewall-cmd --permanent --policy ban-pre-routing --add-egress-zone HOST
sudo firewall-cmd --permanent --policy ban-pre-routing --set-priority -10
sudo firewall-cmd --permanent --policy ban-pre-routing --add-rich-rule="rule family=ipv4 source address=192.168.178.44 port port=143 protocol=tcp reject"

仍然没有效果。我的 *.44 主机仍然可以连接到机器。如果我省略该port port=143 protocol=tcp部分,它会阻止机器使用 ssh - 但仍然能够访问端口 143。

更新 4: 使用更新 3 并将策略配置为出口区域 docker,不会产生差异。我的配置现在如下所示:

$ sudo firewall-cmd --list-all-policies
allow-host-ipv6 (active)
  priority: -15000
  target: CONTINUE
  ingress-zones: ANY
  egress-zones: HOST
  services: 
  ports: 
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 
        rule family="ipv6" icmp-type name="neighbour-advertisement" accept
        rule family="ipv6" icmp-type name="neighbour-solicitation" accept
        rule family="ipv6" icmp-type name="redirect" accept
        rule family="ipv6" icmp-type name="router-advertisement" accept

ban-pre-routing (active)
  priority: -10
  target: CONTINUE
  ingress-zones: ANY
  egress-zones: docker
  services: 
  ports: 
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 
        rule family="ipv4" source address="192.168.178.44" port port="143" protocol="tcp" reject

docker-forwarding (active)
  priority: -1
  target: ACCEPT
  ingress-zones: ANY
  egress-zones: docker
  services: 
  ports: 
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 

对于区域:

$ sudo firewall-cmd --list-all --zone=public
public (default, active)
  target: default
  ingress-priority: 0
  egress-priority: 0
  icmp-block-inversion: no
  interfaces: 
  sources: 
  services: dhcpv6-client ssh
  ports: 
  protocols: 
  forward: yes
  masquerade: no
  forward-ports: 
        port=143:proto=tcp:toport=143:toaddr=172.18.0.2
  source-ports: 
  icmp-blocks: 
  rich rules: 

$ sudo firewall-cmd --list-all --zone=drop
drop
  target: DROP
  ingress-priority: 0
  egress-priority: 0
  icmp-block-inversion: no
  interfaces: 
  sources: 
  services: 
  ports: 
  protocols: 
  forward: yes
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 

$ sudo firewall-cmd --list-all --zone=docker
docker (active)
  target: ACCEPT
  ingress-priority: 0
  egress-priority: 0
  icmp-block-inversion: no
  interfaces: br-c5f172e4effe docker0
  sources: 
  services: 
  ports: 
  protocols: 
  forward: yes
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 
ubuntu
  • 1 个回答
  • 83 Views
Martin Hope
The ScaryJello
Asked: 2025-03-20 23:09:50 +0800 CST

使用 GAWK 替换文件中的字符串问题

  • 7

我有一个程序,它会针对新服务器安装运行一组命令,我需要为每个安装更改文件中的条目。我们需要将默认 DNS 从 127.0.0.X(由于安装时没有互联网连接,因此默认为 127.0.0.X)更改为 8.8.8.8

我使用了以下命令:

sudo awk '{sub(/#DNS=/,"DNS=8.8.8.8")}' /etc/systemd/resolved.conf

然而这似乎在 gawk/new OS 版本下不起作用。

sudo gawk '{gensub(/#DNS=/,"DNS=8.8.8.8")}' /etc/systemd/resolved.conf

我做错了什么?有没有更好的方法来更改默认 DNS 条目?

当前服务器操作系统:Ubuntu 24.04.2-live-server

以前的服务器操作系统:Ubuntu 20.04.6-live-server

编辑:

样例行输入文件:

#DNS=
#FallbackDNS=
#Domains

该命令应该找到上面的第一行并将其替换为,DNS=8.8.8.8但是事实并非如此。

期望输出:

DNS=8.8.8.8
#FallbackDNS=
#Domains

当我运行 awk 命令时,文件仍然显示:

#DNS=
#FallbackDNS=
#Domains

此外,它应该只查找和替换完全匹配的#DNS=

#DNS=用什么命令和语法来替换DNS=8.8.8.8?

ubuntu
  • 2 个回答
  • 186 Views
Martin Hope
Quora Feans
Asked: 2025-03-19 21:31:50 +0800 CST

崩溃后,Ubuntu 启动进入启动菜单

  • 6

崩溃(浏览器冻结)后,我尝试硬重置,在启动时出现了这个屏幕,我无法通过按 Enter 来绕过它。

以前也发生过这种情况,经过多次尝试并按下多个按钮后,它最终再次启动,但我不确定为什么

我的笔记本电脑以前装有 Windows,但是我将其删除并安装了 Ubuntu。

这里发生了什么事?

启动菜单

ubuntu
  • 1 个回答
  • 50 Views
Martin Hope
sfzhang
Asked: 2025-03-14 17:35:49 +0800 CST

用户 systemd 退出并删除了信号量

  • 5

我使用一项systemd服务在 Ubuntu 20.04 启动时启动几个进程。

# MyApp start app service
[Unit]
Description=MyApp start service
Requires=network-online.target
After=network-online.target

[Service] 
Type=simple
ExecStartPre=/bin/sleep 20
ExecStart=/etc/init.d/MyApp.sh start
ExecStop=/etc/init.d/MyApp.sh stop
LimitMEMLOCK=infinity
LimitCORE=infinity
RemainAfterExit=yes

User=admin

[Install]
#WantedBy=multi-user.target
#WantedBy=graphical.target
WantedBy=basic.target

我的所有进程都在系统启动后启动。然而,几分钟后,用户级systemd退出并删除了我的进程创建的所有信号量。

看来我可以设置RemoveIPC=No配置来/etc/systemd/logind.conf阻止用户systemd删除信号量。

但是,用户为什么会systemd退出?我应该使用命令sudo loginctl enable-linger admin来阻止它退出吗?

谢谢!

ubuntu
  • 1 个回答
  • 93 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve