From 4ca8c90e5e49ba2053d9dbc2776488b82f2b40a7 Mon Sep 17 00:00:00 2001 From: think Date: Wed, 6 May 2026 20:51:27 +0800 Subject: [PATCH] fix: Allow TUN mode to auto-enable for NOPASSWD sudo users on Linux Previously, AllowEnableTun() only checked if LinuxSudoPwd was non-empty, which is always null on startup. This caused the password dialog to always appear when enabling TUN mode, even for users with NOPASSWD sudo configured. Add a check using 'sudo -n true' to detect NOPASSWD configuration. This allows users with NOPASSWD sudo to auto-enable TUN mode without being prompted for a password on each startup, matching the behavior of Windows (which auto-enables when run as administrator). Fixes behavior discussed in #7116 and #8069. --- .../ViewModels/StatusBarViewModel.cs | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs b/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs index 0ce40dbb..944ca5e6 100644 --- a/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs @@ -503,7 +503,27 @@ public class StatusBarViewModel : MyReactiveObject } else if (Utils.IsLinux()) { - return AppManager.Instance.LinuxSudoPwd.IsNotEmpty(); + if (AppManager.Instance.LinuxSudoPwd.IsNotEmpty()) + return true; + // Check if sudo is configured with NOPASSWD + try + { + var psi = new ProcessStartInfo + { + FileName = "/usr/bin/sudo", + Arguments = "-n true", + RedirectStandardOutput = true, + RedirectStandardError = true, + UseShellExecute = false, + }; + using var proc = Process.Start(psi); + proc?.WaitForExit(); + return proc?.ExitCode == 0; + } + catch + { + return false; + } } else if (Utils.IsMacOS()) {