What is the recommended way of starting an app after log-in?

Hello,

I am using the app Ryzen Controller to adjust the TDP of my Laptop CPU. Unfortunately the app needs sudo to run.

What is the recommended way to start the app after logging in, without the need to enter my sudo password?

Command:
sudo ‘/opt/Ryzen Controller/ryzen-controller’ --no-sandbox

System:
Manjaro KDE latest stable
X11

Hi @SilentEYE, and welcome!

I’d add the command to the sudoers for your user, to be able to run that command withoput a password and then just add the command the a .desktop file in $HOME/.config/autostart/

Or you can add the command with a systemd unit.

Or you can use your DE’s way of configuring it. (Which I suspect will do #1)

More info:

https://wiki.archlinux.org/title/Sudo#Configuration

https://wiki.archlinux.org/title/Autostarting

Hope it helps!

1 Like

Startup item, as a bash script:

#!/bin/bash
echo MYSUPERBPASSWORD | sudo ‘/opt/Ryzen Controller/ryzen-controller’ --no-sandbox

Menu>Autostart>

Never thought of this. But I wouldn’t recommend it, as it means storing your root password in plaintext. Rather hash it or something.

Maybe a systemd service.

https://wiki.archlinux.org/title/Systemd

Okay, so we have mkpasswd2…

mkpasswd2 -m sha512crypt
1 Like

I like that a lot more!

How to put the password in the line? :stuck_out_tongue:

Still using this string, get the hash first (AES 256 in this case):

echo "MYSUPERBPASSWORD" | openssl enc -base64 -e -aes-256-cbc -salt -pass pass:SuperS3curePassw0rd! -pbkdf2
U2FsdGVkX18hLXXie9ls54oAUT3VbtE7p1W3R+e/MPv/GSvuzbaAkXvz956gSXUj

Of course, the -pass pass: value can be your choice. Just be sure it’s remembered.

And the command to decrypt it would then be:

echo U2FsdGVkX18hLXXie9ls54oAUT3VbtE7p1W3R+e/MPv/GSvuzbaAkXvz956gSXUj | openssl enc -base64 -d -aes-256-cbc -salt -pass pass:SuperS3curePassw0rd! -pbkdf2

For example:

$ echo U2FsdGVkX18hLXXie9ls54oAUT3VbtE7p1W3R+e/MPv/GSvuzbaAkXvz956gSXUj | openssl enc -base64 -d -aes-256-cbc -salt -pass pass:SuperS3curePassw0rd! -pbkdf2
MYSUPERBPASSWORD

So, then have that along with your command, it would be:

echo U2FsdGVkX18hLXXie9ls54oAUT3VbtE7p1W3R+e/MPv/GSvuzbaAkXvz956gSXUj | openssl enc -base64 -d -aes-256-cbc -salt -pass pass:SuperS3curePassw0rd! -pbkdf2 | sudo ‘/opt/Ryzen Controller/ryzen-controller’ --no-sandbox

Or so I’m guessing anyway.

Erm… guys… why so complicated?

echo '%wheel ALL=(ALL) NOPASSWD: /opt/Ryzen_Controller/ryzen-controller' | sudo tee /etc/sudoers.d/nopw

Et voila, sudo will not prompt for a password on that command.

1 Like

My explanation wasn’t for OPs question, but for @Ben.

@SilentEYE This :point_up: is what I meant by adding it to sudoers.

@megavolt @Mirdarthos +Ben
Thank you. I entered the command into the console.
After that I created a file with the name ryzen-controller-startup.sh in my personal folder.

Inside is:
#!/bin/bash
sudo ‘/opt/Ryzen Controller/ryzen-controller’ --no-sandbox
exit 0

  • I made the file executable through Dolphin
  • added the script into KDE Autostart

rebooted and nothing happend.

Executing the file with terminal says:
sudo: ‘/opt/Ryzen’ not found (also without the ’ it says sudo: /opt/Ryzen not found)

Editing the script to
#!/bin/bash

  • sudo ‘/opt/Ryzen_Controller/ryzen-controller’ --no-sandbox*
  • exit 0*
    gives the error: … command not found (with and without ')

Try it like:

sudo /opt/Ryzen\ Controller/ryzen-controller --no-sandbox

The space needs to be escaped.

1 Like

:bangbang: Tip: :bangbang:

When posting terminal output, copy the output and paste it here, wrapped in three (3) backticks, before AND after the pasted text. Like this:

```
pasted text
```

Or three (3) tilde signs, like this:

~~~
pasted text
~~~

This will just cause it to be rendered like this:

Sed
sollicitudin dolor
eget nisl elit id
condimentum
arcu erat varius
cursus sem quis eros.

Instead of like this:

Sed sollicitudin dolor eget nisl elit id condimentum arcu erat varius cursus sem quis eros.

Alternatively, paste the text you wish to format as terminal output, select all pasted text, and click the </> button on the taskbar. This will indent the whole pasted section with one TAB, causing it to render the same way as described above.

Thereby increasing legibility thus making it easier for those trying to provide assistance.

For more information, please see:


:bangbang::bangbang: Additionally

If your language isn’t English, please prepend any and all terminal commands with LC_ALL=C. For example:

LC_ALL=C bluetoothctl

This will just cause the terminal output to be in English, making it easier to understand and debug.

Thank you! That works now in the console, but in the terminal still asks me for a sudo password AND the script is not starting after login.

Should the script also work, when I execute it through Dolphin file manager, because Dolphin gives an error message at the top: execvp: Error in the format of the program file

When you say you placed it in autostart, I’m presuming you added it in System SettingsWorkspaceStartup and shutdown.Autostart, as in the screenshot below?

Copy that script to ~/.config/plassma-workspace/env/:

cp ~/ryzen-controller-startup.sh ~/.config/plassma-workspace/env/

According to how I understand it.

I’ve got 2 scripts there myself, both working a charm.

1 Like

I “think” you need to fix your sudoers entry to use the same path as you use in your script :stuck_out_tongue_winking_eye:

sudoedit /etc/sudoers.d/nopw

But TBH, if a script needs to run as root you should make your service file as a system-service instead of a user-service, because system-services are executed as root already.

Does that ryzen-controller provide a GUI window or status icon?
(If that is the case you will run into problems with system-services because it would need access to your GUI-Session.)


See: Desktop Application Autostart Specification

1 Like

After copying the file into that folder the device hang in the login process after entering my password.

I did the following command

cp Ryzen-Controller-Startup.sh ~/.config/plasma-workspace/env/   

I had to remove the file with alternative Login (ALT +F2)

BTW. I solve the password prompt problem by changing the previously given command to

%wheel ALL=(ALL) NOPASSWD: /opt/Ryzen\ Controller/ryzen-controller --no-sandbox

1 Like

I fixed the sudoers thing in the meantime.

The app has a GUI and a status icon.

The syntax is:

cp <source> <destination>

Where:

  • <source> is the already existing file you wish to copy; and
  • <destination> is the directory you wish to copy the file to.

In the command you provided:

It you don’t specify in which directory the source file is. So unless the file is in the same directory from which the command is run, it won’t work.

Also, files, actually everything in Linux is case-sensitive. So:

is not the same as:

So double-check and correct anything that’s incorrect, because it all looks OK, to me.