[Solved]Total newbie question

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Post Reply
FrankB
Level 1
Level 1
Posts: 11
Joined: Sun Jan 28, 2024 5:18 am

[Solved]Total newbie question

Post by FrankB »

Hello, I seem too stupid to understand scripts in linux so I need some help please
from my home dir I want to run a command in a subdir of downloads, However, to run this command I need root permissions. I would love to have a link on my desktop to just run the command so simplify my work but I have no idea how to do that
Last edited by FrankB on Thu Feb 15, 2024 9:13 am, edited 1 time in total.
mikeflan
Level 17
Level 17
Posts: 7162
Joined: Sun Apr 26, 2020 9:28 am
Location: Houston, TX

Re: Total newbie question

Post by mikeflan »

to run this command I need root permissions.
Maybe we should talk about that to see if it is really true.

But regardless, it sounds like you want to do this:
Pass the password to a script running sudo:
viewtopic.php?t=405273
dave0808
Level 5
Level 5
Posts: 987
Joined: Sat May 16, 2015 1:02 pm

Re: Total newbie question

Post by dave0808 »

To add a menu option, right click on the start menu, click on Configure, click on Menu tab, click on the button "Open the menu editor". Then create a new item.

Unless the script is specifically for performing some administrative task, you should not be running it as root. That way, you're giving the script full access to your system to do anything that it likes. Presumably you didn't write the script and don't have enough knowledge to understand what the script is actually doing, so don't give it full access to your system. Not unless you really trust it 100%.

Possibly there's a permissions problem. In the file manager, you can right click on the script and look at the properties, then permissions. There are a bunch of permissions for the "Owner", which should be you. In order to "run" the program, you need execute permission. If the file is owned by some other user, or there is just a number shown as the "Owner" then the ownership of the file needs changing. I don't think that can be done with the GUI file manager, so will require use of the command line sudo chown $USER <filename> where <filename> is the exact name of the file including any extension. You'll need to supply your password when prompted because changing file ownership is itself an admin task.
User avatar
Koentje
Level 7
Level 7
Posts: 1581
Joined: Tue Jan 04, 2022 6:23 pm
Location: Netherlands

Re: Total newbie question

Post by Koentje »

echo <passwd> | sudo <command>
Image
rickNS
Level 9
Level 9
Posts: 2981
Joined: Tue Jan 25, 2011 11:59 pm

Re: Total newbie question

Post by rickNS »

Koentje wrote: Sun Jan 28, 2024 2:43 pm echo <passwd> | sudo <command>
That, and as linked above, and as found elsewhere on the web does NOT work for me.

Code: Select all

$ echo "password" | sudo -S sleep 1 && fdisk -l
[sudo] password for rick: fdisk: cannot open /dev/sda: Permission denied
This however does,

Code: Select all

$ sudo -S <<< "password" fdisk -l
[sudo] password for rick: Disk /dev/sda: 232.89 GiB, 250059350016 bytes, 488397168 sectors
Disk model: Samsung SSD 850...etc.
Last edited by rickNS on Wed Feb 14, 2024 6:07 pm, edited 1 time in total.
Mint 20.0, and 21.0 MATE on Thinkpads, 3 X T420, T450, T470, and X200
dave0808
Level 5
Level 5
Posts: 987
Joined: Sat May 16, 2015 1:02 pm

Re: Total newbie question

Post by dave0808 »

Koentje wrote: Sun Jan 28, 2024 2:43 pm echo <passwd> | sudo <command>
The OP may well be on a single-user machine, but this is not good for security.

The user will be typing the password into the command line in a way that is visible to anyone looking over their shoulder, or to anyone that can gain access to the shell history. Or if this is put into a script, the password is visible to anyone that can read the file.

Also, the system maybe setup such that sudo doesn't actually require a password. If it's necessary to get prompted in the GUI world, then one option would be to use the --askpass argument to sudo instead.
User avatar
Koentje
Level 7
Level 7
Posts: 1581
Joined: Tue Jan 04, 2022 6:23 pm
Location: Netherlands

Re: Total newbie question

Post by Koentje »

I used it this way in scripts in the beginning and worked for me, later i added the scripts to sudoers. But with every script my sudoers got bigger and bigger and when i got sick and tired of typing my password everytime on the terminal i changed /etc/sudoers. Now i only need passwords for GUI programs. (synaptic, updates etc).
And since i work a lot with midnight commander i change it's wrapper so i can start it in normal, sudo or root mode. This way it changes colors and prompt each mode so i visually see i'm in normal/sudo/root mode. (btw for root i still need password)

normal
Image

sudo
Image

root
Image
Image
FrankB
Level 1
Level 1
Posts: 11
Joined: Sun Jan 28, 2024 5:18 am

Re: Total newbie question

Post by FrankB »

Thank you for all your ideas,
The echo <passwd> | sudo <command> works perfectly. As people asked here, I know what I want, I want to start the vpn which is preconfigured and II can give all the parameter on the command line when I am in the subdirectory. I just wanted to have a script to do that from the desktop
Post Reply

Return to “Scripts & Bash”