Is there any way to make programs ask for password when root is required? For example I want to extract some files with File Roller into /usr/share/
where apparently root is required but instead of the error that it gives me I would like a password prompt.
4 Answers
To directly answer your question: No, there is no way (as far as I am aware) to make a program to ask for a password instead of failing when it doesn't have enough permissions to perform an operation. There are two options:
Some programs are aware that they need administrative privileges for some operations and ask for a password before doing something (i.e. Software Center asks for a password before installing programs).
Most other programs need to be started with necessary privileges. As it has been mentioned, you need to use
sudo [command]
(in terminal),gksu [command]
(in Gnome/Unity) orkdesu [command]
(in KDE) for that.
The usual way is to go in command line mode (alt + F2 xterm
, or dash terminal) then use gksudo file-roller
and enter your password.
sudo and gksudo will give you root privileges.
-
-
Just a guess, but if you open a terminal, why not use sudo instead of gksudo? Nov 7, 2011 at 19:17
You'd have to start File Roller using gksu
as mentioned by the previous user. When you add items to your startup bar, you can use a command such as faxanswer that requires privileges:
gksu faxanswer ttyS4
If you are using that File Roller once to update stuff in /usr/share
, it's better to just use the Run command than create a permanent icon.
-
Thanks for the edits Scott. I just tried and indeed gksu and gksudo both work... Oct 30, 2011 at 21:54
Is there any way to make programs ask for password when root is required?
Yes - with the helper scripts.
Here is an example with the bash copy (cp). The copying (backup) is wrapped in the perl script to check the owner of the file. The script is using the perl stat /1/ command. Here the script is called from the KDE service menu /2/. If the file is owned by the root /3/ then the KDE frontend for sudo is used /4/, /5/.
backup.pl:
usage: "backup.pl filename"
#!/usr/bin/perl -w
$FILENAME = $ARGV[0];
$MARKER = "_Backup_";
($DAY,$MONTH,$YEAR) = (localtime)[3,4,5];
$DAY_STAMP = sprintf '%04d%02d%02d', $YEAR+1900, $MONTH+1, $DAY;
for ( $I=0; $I<101; $I++ ) {
if ( $I > 99 ) { die system ("kdialog --sorry '...too many copies'"); }
$INDEX = sprintf '%02d', $I;
$NEW_NAME = $FILENAME . $MARKER . $DAY_STAMP . $INDEX;
last unless (-e $NEW_NAME);
}
$UID = (stat("$FILENAME"))[4];
@Q_COPY_COMMAND = ("\"", "cp", "$FILENAME", "$NEW_NAME", "\"");
@COPY_COMMAND = ("cp", "$FILENAME", "$NEW_NAME");
if ( $UID == 0 ) {
system ("kdesudo bash -c @Q_COPY_COMMAND");
} else {
system ("@COPY_COMMAND");
}
Links: