Never Ending Security

It starts all here

Automatically run a script when logging into Linux

 Startup Script

There are circumstances where you wish to have a startup script that run automatically when you log in to Ubuntu Desktop. Such a script can configure various user-specific or system-wide settings on your Ubuntu system, upon user’s desktop login.

In Linux, there are start-up scripts named ~/.bash_profile, ~/.bashrc, or ~/.profile which get executed when you start a shell. However, in Ubuntu Desktop, such start-up scripts get executed when you open up a terminal window, but NOT when you log in to Ubuntu Desktop GUI. Also, when you open multiple terminal windows, these kinds of start-up scripts are executed as many times, in order to initialize user’s shell environment in terminal windows.

If what you want is to run a script at the time of user’s Ubuntu Desktop login, you can follow this guideline.

Create a XDG configuration file for the start-up script you want to run.

$ nano ~/.config/autostart/my_script.desktop

[Desktop Entry]
Name=My Script

The above XDG configuration file will set up “user-specific” auto-start. If you want all users to use the same start-up script “system-wide”, create a similar XDG configuration file in the following location instead.

$ sudo nano /etc/xdg/autostart/my_script.desktop

[Desktop Entry]
Name=My Script
Exec=sudo /sbin/

If the start-up script requires sudo access like an above example, you will need to set up password-less sudo

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s