You could simply echo (with elevated privileges, of course) directly to the /etc/sudoers file:
nickw444@laptop ~ $ sudo -i
nickw444@laptop ~ $ echo 'nickw444 ALL=(ALL:ALL) ALL' >> /etc/sudoers
(note the tab character between the username and the first ALL)
Or, for a script:
#!/bin/bash
sudo echo 'nickw444 ALL=(ALL:ALL) ALL' >> /etc/sudoers
Then save to somefile.sh and run ./somefile.sh from a terminal window.
To add multiple users, change the script to this;
#!/bin/bash
while [[ -n $1 ]]; do
sudo echo "$1 ALL=(ALL:ALL) ALL" >> /etc/sudoers;
shift # shift all parameters;
done
Then, run the script like this (assuming you saved it as addsudousers.sh):
nickw444@laptop ~ $ sudo ./addsudousers.sh username1 username2 somenewadmin bob
that is, space-separated.
To read the names from a file:
nickw444@laptop ~ $ sudo ./addsudusers.sh `cat listofusers.txt`
listofusers.txt should also be space-separated.
分享到:
相关推荐
A tutorial on adding columns to Explorer’s details view via a column handler shell extension.(13KB)
Adding Classifications to Web Services.
Adding filters to the Open File dialog(24KB)
XKCDIFY! Adding flair to boring Matlab Axes one plot at a time.zip
USB4 1.0 ECN - Adding Condition to Deactivate RS-FEC Encoding.
A class for adding icons to the system tray(120KB)
Taking the pain out of adding a horizontal scrollbar to a listbox.给列表框添加水平滚动条
Adding a search facility to your website
Adding feature flags to hide features from users 196 Implementing Socialite to allow users to login with Facebook 201 Adding custom middleware to protect user admin area 206 Using Laravel to set up a ...
Adding Password Management to Your Templates(cloudstack)
Adding a Node to a 10g RAC Cluster 希望对那些ORACLE使用者有点作用
ActiveX Script脚本组件 The ActiveX Script Components is a small collection of native Delphi VCL components that are designed to make adding scripting to your programs as easy as possible.
what Drupal is, installing and configuring Drupal, creating and managing content, managing users, adding functionality to your web site through Drupal modules, and more advanced topics on using ...
Adding white noise to a signal with fixed SNR
In the second half we get several samples working to show you how everything comes together. Vector maps (line maps) Vs satellite or aerial imagery Spatial Databases PostgreSQL OGC services: Web Map ...
Adding a Build Banner to ASP.NET Pages。
It starts off by building a basic IMDB clone and adding users who can register, vote on their favorite movies, and upload associated pictures. You will learn how to use the votes that your users have...
Adding ODBC support to a new application使你的程序添加ODBC支持
VTK\Adding_Components_to_VTK_Designer_2
DM81xx AM38xx Adding External Decoders to V4L2 Capture Driver