The very same ls aliases are defined on both machines:

$ cat ~/.bash_aliases | grep -e "alias ls=" -e "alias l=" -e "alias lll="
alias ls='\ls --kibibytes --color=always --group-directories-first'
alias l='ls'
alias lll='l -la'

Linux Mint (18.1)

(I sit at this machine.)

$ sudo -s
[sudo] password for ...

$ lll
(very long list of files)

GNU/Linux Debian Stretch (9, testing)

(I ssh to this machine.)

$ ssh username@ip_address_of_server -p port_number

$ sudo -s
[sudo] password for ...

$ lll
lll: command not found


How do I achieve the goal to have my personal aliases sourced when sudo -s on Debian like it works on Linux Mint?

sudo -s explanation

sudo -s sources aliases on my Linux Mint, whereas sudo -i or su or su - do not.

It is working for my purposes on Linux Mint, I have a lot of useful aliases defined and I want it also to work on my Debian server.


You need to source the .bash_alias file in the right shell initialisation file. The initialisation file varies on how the shell is started. And calling it on via ssh and on a local machine are different. But then calling it again with sudo -s makes it the same on both machines, because it starts an interactive non-login root shell. But to get the same aliases, you need the have the same definitions.

If you stick to sudo -s, it's enough to source your .bash_aliases file in the ssh user's .bashrc. So it's enough to add this line to ~/.bashrc:

. ~/.bash_aliases

Notice that the lll alias works on your Mint before you sudo -s and it won't do so on Debian, because that's an ssh session, so a login shell, while on Mint it's just interactive. If you want the aliases to be available right away on the ssh Debian, you'll have to add another sourcing to your .profile file.

This is quite convoluted and to get the whole picture, you need to do some reading and learn about login and interactive shells. man bash has it all. You can take a look at this answer to have an idea of what this is about. Don't skip the comments below that answer!

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.