It needs be root for some command and not for other commands.
fdisk -l
ls -l
cd /etc
For fdisk -l need root password.
After fdisk -l i want to be again a normal user.
How can i this with shell script?
It needs be root for some command and not for other commands.
fdisk -l
ls -l
cd /etc
For fdisk -l need root password.
After fdisk -l i want to be again a normal user.
How can i this with shell script?
if you call su -c "fdisk -l" su will prompt for root password.
If you want to avoid password prompts consider using sudo, or allow ssh to root@localhost for user with non-interactive (public/private keys) authentication.
sudo is good cause you can allow users in particular groups to run specific commands (ie it's quite configurable on who can do what as root (or any other user for that matter) ).
I want to type root password for one time for all admin commands.
After that i want to exit to be normal user.
Then being normal user i will continue with other commands.
Can you post a sample script to do this?
set sudo with NOPASSWD for your own account, with that, when you run fdisk with sudo in your account, it will run as root.
(root) NOPASSWD: /usr/sbin/fdisk
So change your script to:
sudo /usr/sbin/fdisk -l
ls -l
cd /etc
I want to give password for root.
But i don't want to be root for normal command.
As we do in terminal,typing root password type admin command then doing exit type normal command.
Is there any other way except sudo?