I am running

Linux 4.4.0-116-generic Ubuntu + KDE ( x86_64 GNU/Linux )

I want to run an alias named ksession that kills a particular session. At the same time I want that only I can run this alias and nobody else. So, I found .bashrc file under /root directory and added an alias by the name ksession in it, then tried running source command with no success and following errors :

amit@C0deDaedalus:~$ source /root/.bashrc
bash: /root/.bashrc: Permission denied

amit@C0deDaedalus:~$ sudo source /root/.bashrc
sudo: source: command not found
  1. Is there any way to source that file being a non-root user ?

  2. I want to run the alias being a non-root user. Can I run it with sudo like this ?

    $ sudo ksession

    I tried that and failed with error :

    amit@c0deDaedalus:~$ sudo ksession
    sudo: ksession: command not found
  3. If not, Is there any workaround for running root aliases from a non-root user ?

1 Answer 1


Root shouldn't need aliases. If you want something private, then don't start changing things in other user's accounts (root's in this case).

Just write ksession as a shell script and use sudo in the script to when needed. Put the script in a private directory, for example $HOME/bin, and make sure that this directory is part of your $PATH and that the script is executable.

Alternatively, write it as a shell function and put it in your ~/.bashrc file. The function may use sudo when needed.

Alternatively, write it as an alias and put it in your ~/.bashrc file. The alias may use sudo when needed.

Your sudo source ... command does not work since source is a bash built-in command and sudo expects an external command.

Even if it had worked, the alias would not have been activated in the calling shell as the command that sudo invokes is running in its own sub-shell.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.