Shutdown in linux without sudo [closed] - linux

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I am making a project in linux which needs to shutdown the system when process is finished. How can it be done without the need to provide password?

If your program (e.g. in C, C++, Ocaml, ...) is compiled into an ELF executable you could make it setuid (then use seteuid(2), sync(2), reboot(2) syscalls, or better yet execve(2) on /sbin/poweroffor other commands). But be careful (be afraid of security holes, ...)
You'll need to code your program very carefully, and you'll need to be root to install your program with the setuid bit set (e.g. chmod u+s as root). But users won't need to be root to run the installed executable.
You should read Advanced Linux Programming (and carefully several man pages for important syscalls(2)). Please take time to understand the setuid mechanism, which is tricky and can be used dangerously.
And you could simply install and configure your system to start your program as root (e.g. by configuring your init or systemd, or some crontab, or some startup in /etc/rc.local etc etc etc ...)
Read also credentials(7) and capabilities(7)

On distributions with recent systemd, it is possible to shut down the system if no other user is logged in. This requires however a full-blown login session via systemd-logind, of which I don’t know whether you have it.
If your process lives in such an environment, you can call systemctl poweroff or systemctl reboot. The context of your process (running in a full blown login session, if no other user is logged in) will allow you to shut the system down.

If you use visudo and add
%group_name ALL=(ALL) NOPASSWD: /sbin/shutdown
you can use shutdown without providing a password.
However you will still need sudo.
But you could create an alias in .bashrc which replaces sudo shutdown now with shutdown
How to create an alias:
http://community.linuxmint.com/tutorial/view/891
of course this works with every other command as well

Related

How to make a program user directly comes into when turns on PC? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
I want to build a gadget with PC-boards like raspberry and Linux(or Windows) OS. And when user turns on the gadget sees my company name, and directly goes to my program and couldn't exit from that.something like ATM machines.
How can I do that?
What is this topic name and where can I find sources and guides?
You can hard-code your user-space process to run after bootup by updating the init script. You can run it as a daemon process and block all signals to it by the user. You can further disable other services and application processes like login process if you want the application to be accessed by everyone.
Link: Creating a Kiosk with Linux
On Linux, you just configure the system to run your specialized program. This can be as simple as configuring (e.g. in some /etc/rc.local or /etc/rc.2/ ...) (or even replacing or enhancing) the init program, or configuring the startup of the X11 server.
There are also several "kiosk oriented" Linux distributions. Details about configuration of the init process may be distribution specific. And systemd is now often a replacement of init and is configured specifically.
So you need first to choose some Linux distribution then dive into its documentation.
BTW, crontab(5) knows about #reboot so can be a way to customize the startup procedure
You first should learn more about Linux programming and its system administration (which is distribution specific). If you don't know Linux, I strongly suggest you to install Linux on your laptop and become familiar with it.
Maybe you should look into raspbian
Have a look at the current issue (#93) of the fullcircle magazine (as pdf or epub available). It contains an article about how to install a kiosk mode for ubuntu. It should be easily adoptable to your usecase (replace your app with firefox as mentioned in the article).
Disclaimer: I'm the founder of the opensource Webconverger Web kiosk project.
Debian based Webconverger uses the inittab to manage services. I highly recommend you work from the opensource Webconverger project and do not roll you own kiosk.
The new version of Webconverger for Rpi2 and PCs will be using systemd exclusively.

GNU Screen can't find applications after log out [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
I recently installed Ubuntu 12.04 sever on a new box. I ssh in, run a command (a do loop iterating over a perl script that forks off several processes each running an application [blastn] on the provided data), and detach using Ctrl-a d. When I run screen -r to resume, no problem, the loop is running happily. When I log out of my ssh session and log back on, I can still resume the screen session with screen -r, but now the loop has terminated with error messages stating that the application can't be found and/or the perl script can't be found. I've tried giving the full path to the perl script to my perl command (i.e. not using tilde), but no dice. Still gets lost after ssh logout / logon.
It seems this is particular to my Ubuntu server. Running the exact same loop / perl script forking off processes / applications through ssh into my Mac OS X box, it finishes happily even after logging out from ssh, so I wonder if this has something more to do with my Ubuntu server than GNU screen. Much searching online has yielded no answer, however, so I would appreciate any help that you may be able to offer.
I can only guess you may have an encrypted home directory which as decrypted version is mounted during your login time. As soon as the last login terminates, the decrypted version gets unmounted and your running processes have no access anymore to the files in your home directory.
You can check this by typing mount | grep ^/home/. If this shows ecryptfs as type of the mount, then this is the case.
If this shows nothing (or a file system type like ext3 or similar), then my guess is wrong.

Getting IO privileges in Linux [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
I have installed flashrom software. When i try to run sudo flashrom command it gives me "Could not get I/O privileges (Operation not permitted). You need to be root" error. Also I tried su command to switch root and run again. I also tried sudo -i command to login as root. However any of them did not work
#if defined (__OpenBSD__)
msg_perr("If you are root already please set securelevel=-1 in /etc/rc.securelevel and\n"
"reboot, or reboot into single user mode.\n");
#elif defined(__NetBSD__)
msg_perr("If you are root already please reboot into single user mode or make sure\n"
"that your kernel configuration has the option INSECURE enabled.\n");
#endif
Reading this from the FlashRom.org pastebin site should give some insight.
This is the only file in Flashrom that contains the line, "You must be root"
Therefore, in my opinion, this is the only place the error can be coming from.
I changed secure boot option in bios settings as disabled. So I can run the flashrom program. But it gives this output.
WARNING! You seem to be running flashrom on an unsupported laptop.
Laptops, notebooks and netbooks are difficult to support and we
recommend to use the vendor flashing utility. The embedded controller
(EC) in these machines often interacts badly with flashing. See the
manpage and http://www.flashrom.org/Laptops for details.
If flash is shared with the EC, erase is guaranteed to brick your
laptop and write may brick your laptop. Read and probe may irritate
your EC and cause fan failure, backlight failure and sudden poweroff.
You have been warned.
So there is nothing to do. I have to search another tool to flash my bios

How to install a program in linux for all users not only for root? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I installed the shrewsoft vpnmanger on my linux (crunchbang kernel 3.2.0-4 amd64) the problem is, that somehow it can only be started as sudo. Can someone explain how i can fix this?
sudo /usr/local/sbin/iked&
How can I change the iked installation so that it is available for each user?
Thanks
It's just about the paths a normal user's shell search for commands. But normally it makes sense that those commands located in a sbin dir are not accessible by typing just the command's name. Those commands need access to protected resources that are only accessible by root.
But if you have the luck that you can gain the full rights by means of sudo you can simply create an alias via
alias iked="sudo /usr/local/sbin/iked"
and add it into your shell's resource file.
To make the full command accessible to all users by simply typing iked you can create a little bash script named iked with content
#!/bin/bash
sudo /usr/local/sbin/iked
and place it in /usr/local/bin.
Of course that implies an appropriate /etc/sudoers file and that the execute permission of iked is set.
try copying or symlinking in it in /usr/bin.
and see if it work for the user then, if it has a global log file (I don't know about this app so not one to comment) but assuming it has some log in /var/log/iked.log and its been written by root you will have permssion issues by another user, so chown it to some neutral group like users or something.:
Try here it may give you more info, I can see you could try:
/usr/bin/iked -d 4
But from what I read it does have a log in /var/log and yep that permission issue would be the primary issue specially if root was the first user to run this app.

PuTTY: Change default SSH login directory [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
In Windows, I use PuTTY to log in a Linux-based remote server via SSH.
Is is possible to change the default directory entry point I get to after I connect and login? (That would be a nice time saver.)
e.g. from server/home/ to server/home/subdir/subdir/
You can also change the directory within PuTTY itself:
Configuration → Connection → SSH
Fill in the "Remote command" field with the following:
cd subdir/subdir ; /bin/bash
Add cd subdir/subdir to ~/.bashrc or ~/.bash_profile, or
change the home directory of the user.
You could use screen to keep your current directory by always logging into the same screen session.
Add the screen command with parameters to your putty saved session under SSH>Remote Command.
See the screen documentation for which parameters to use.
screen -R -O -t mysession -S mysession -f
Depends on a lot of things. Mainly the server operating system. Most SSH servers run Linux or Unix of some flavor. When you connect via any method of remote text login (as SSH is one member of this category) such a system will automatically spawn a shell process to talk to you. That's probably "bash", and it runs various things on startup. Check out
man bash
to learn more. One of the many things you can do is cd to a subfolder.

Resources