1 |
On Sun, Mar 22, 2015 at 03:30:49AM -0400, German wrote |
2 |
|
3 |
> Thanks, I decide to go with sudo on this one. However when I try |
4 |
> to run it, it says: "Username is not in the sudoers file." Where is |
5 |
> this file located and how can I add the user to it? Thanks |
6 |
|
7 |
Here's how it works. "emerge -pv sudo" and decide whic USE flags you |
8 |
need for your situation. I use none of them. The main config file is |
9 |
/etc/sudoers *DO NOT TOUCH THAT FILE*. It'll get overwritten every |
10 |
time that an update of sudo comes along. sudo also reads files in its |
11 |
"include directory", which defaults to /etc/sudoers.d/ which is where |
12 |
you should put your stuff. You can have multiple files in there, and |
13 |
they will be executed in the same order that they sort. *DO NOT EDIT |
14 |
THESE FILES DIRECTLY WITH NANO/VIM/WHATEVER*. Use the command... |
15 |
|
16 |
visudo -f /etc/sudoers.d/filename |
17 |
|
18 |
where "filename" is any legal file name. visudo is a sudo feature that |
19 |
* gets your default editor |
20 |
* edits a *WORKING COPY* of the file you want to change |
21 |
* after you exit the editor, it tests the file syntax |
22 |
* if no sudo syntax errors are found it commits the file |
23 |
* if syntax errors are found, it warns you, and allows you to back out |
24 |
|
25 |
I have a single file /etc/sudoers.d/001 but you can have several files |
26 |
if you want. The desktop's hostname is "d531" and my login is |
27 |
"waltdnes". Adjust correspondingly for your system... |
28 |
|
29 |
waltdnes d531 = (root) NOPASSWD: /sbin/poweroff |
30 |
waltdnes d531 = (root) NOPASSWD: /usr/sbin/hibernate |
31 |
waltdnes d531 = (root) NOPASSWD: /usr/bin/simple-mtpfs -o allow_other /home/waltdnes/tablet |
32 |
waltdnes d531 = (root) NOPASSWD: /usr/bin/fusermount -u /home/waltdnes/tablet |
33 |
waltdnes d531 = (root) NOPASSWD: /bin/cp -f /etc/ssmtp/295.ssmtp.conf /etc/ssmtp/ssmtp.conf |
34 |
waltdnes d531 = (root) NOPASSWD: /bin/cp -f /etc/ssmtp/teksavvy.ssmtp.conf /etc/ssmtp/ssmtp.conf |
35 |
waltdnes d531 = (root) NOPASSWD: /usr/bin/openrdate -n -s ca.pool.ntp.org |
36 |
waltdnes d531 = (root) NOPASSWD: /sbin/hwclock --systohc |
37 |
|
38 |
|
39 |
This format allows the user to run the command, if preceeded by |
40 |
"sudo", and no password is required. Note that the command must be |
41 |
identical to what is set in /etc/sudoers.d/ e.g. |
42 |
|
43 |
sudo /sbin/poweroff |
44 |
|
45 |
I usually launch it from a script in ~/bin to same a lot of typing, |
46 |
and avoid typo errors. For instance, to connect my tablet or smartphone |
47 |
to directory ~/tablet, I have a script ~/bin/tabon |
48 |
|
49 |
#!/bin/bash |
50 |
sudo simple-mtpfs -o allow_other /home/waltdnes/tablet |
51 |
|
52 |
To disconnect from the device I have a script ~/bin/taboff |
53 |
|
54 |
#!/bin/bash |
55 |
sudo fusermount -u /home/waltdnes/tablet |
56 |
|
57 |
To sync my desktop's clock, I have a script ~/bin/settime |
58 |
|
59 |
#!/bin/bash |
60 |
date |
61 |
/usr/bin/sudo /usr/bin/openrdate -n -s ca.pool.ntp.org |
62 |
/usr/bin/sudo /sbin/hwclock --systohc |
63 |
date |
64 |
|
65 |
I have a dialup ISP (295.ca) as emergency backup in case my broadband |
66 |
ISP (teksavvy.com) service goes down. ISP's only let logged in users |
67 |
connect to the standard outbound port. So I need to change the |
68 |
/etc/ssmtp/ssmtp.conf file to point to the approprite ISP's server. My |
69 |
dialup script is... |
70 |
|
71 |
#!/bin/bash |
72 |
sudo /bin/cp -f /etc/ssmtp/295.ssmtp.conf /etc/ssmtp/ssmtp.conf |
73 |
sudo /usr/sbin/pon u295.ca |
74 |
|
75 |
My "dialdown" script is... |
76 |
|
77 |
#!/bin/bash |
78 |
/usr/bin/sudo /usr/sbin/poff |
79 |
/usr/bin/sudo /bin/cp -f /etc/ssmtp/teksavvy.ssmtp.conf /etc/ssmtp/ssmtp.conf |
80 |
|
81 |
|
82 |
|
83 |
-- |
84 |
Walter Dnes <waltdnes@××××××××.org> |
85 |
I don't run "desktop environments"; I run useful applications |