0

I have the computer A (kali linux) where I defined some aliases and functions in the bash_aliases for the user 'test'. I can use these aliases/functions from the computer A without any problem.

With the computer B, I connect to A with SSH command and I try execute aliases/functions I defined. But I get the error "bash: myaliasA: command not found"

Here I see I must add the "shopt -s expand_aliases" command.

I add this in the .bashrc of the computer A (and source .bashrc), but I still get the same error (command not found)

I add this in the .bashrc of the computer B (and source .bashrc), same, I still get "command not found" when I connect with ssh

I don't understand where is the issue :/

In the computer A, when I run the command "shopt" I get :

...
execfail        off
expand_aliases  on
extdebug        off
...

Same in the computer B :

...
execfail        off
expand_aliases  on
extdebug        off
...

From my computer A, I can execute all my alias/functions without any problem.

From my computer B, when I execute this command :

ssh userA@ipofcomputerA -p xxxx "alias"

This command return nothing

But if I execute :

ssh userA@ipofcomputerA -p xxxx "shopt"

I get :

...
execfail        off
expand_aliases  off
extdebug        off
...

The expand_aliases is set to off !

So, I test this :

ssh userA@ipofcomputerA -p xxxx "shopt -s expand_aliases ; shopt ; myaliasA"

and

ssh userA@ipofcomputerA -p xxxx "shopt -s expand_aliases ; shopt ; source .bashrc ; myaliasA"

With this two commands, I get :

...
execfail        off
expand_aliases  on
extdebug        off
...

but I get after "bash: myaliasA: command not found"

I'm going crazy x) haha

Community
  • 1
  • 1
spacecodeur
  • 2,206
  • 7
  • 35
  • 71
  • I suggest to use an interactive shell: `ssh userA@ipofcomputerA -p xxxx bash -ic "alias"` – Cyrus Aug 30 '16 at 06:06
  • Sometimes `~/.bashrc` or `/etc/default/bash` is not set to load ~/.bash_aliases - do you see any mention of it? – jedifans Aug 30 '16 at 06:11
  • @Cyrus, it works ! i get the output of my alias, but I get too this 'warning' : "cannot set terminal process group (-1): Inappropriate ioctl for device" and "bash: no job control in this shell". How can I get the output of my alias without these warning ? :) – spacecodeur Aug 30 '16 at 06:16
  • @jedifans, in .bashrc , the bash_aliases is loaded – spacecodeur Aug 30 '16 at 06:18
  • You will need to check how kali Linux handles sourcing your `~/.bashrc`. `ssh` generally doesn't trigger an interactive shell. Most distros have a scheme in either /etc/profile and/or /etc/bash.bashrc that will trigger the read of your bashrc on ssh login. SuSE does it different than Arch, that does it different than Kali. So check what Kali requires. – David C. Rankin Aug 30 '16 at 06:56
  • The immediate problem is that the entire command line is parsed before `expand_aliases` is enabled. You can force this by replacing the semicolons with newlines IIRC. A better approach altogether is to not require aliases - they are problematic for a number of reasons, including but not limited to this. – tripleee Aug 30 '16 at 09:44
  • I wish I was able to find a better duplicate where this is properly explained, but the comment above should be enough to settle this for you. – tripleee Aug 30 '16 at 09:45
  • Thanks for yours answers ! @tripleee : can you explain what is "newlines IIRC" ? I didnt understand :/ – spacecodeur Aug 30 '16 at 21:19
  • IIRC means ["if I recall correctly"](http://www.urbandictionary.com/define.php?term=iirc). The newline trick is explained e.g. [here](http://stackoverflow.com/questions/1615877/why-aliases-in-a-non-interactive-bash-shell-do-not-work#comment65785947_1615973). – tripleee Aug 31 '16 at 04:23

1 Answers1

-1

Make sure that when you ssh you use the same shell for which the configuration exists, and try to reset in order to reload the .bashrc files.

On a side note, a good way to do this is to open a new tmux session and attach to it everytime you ssh into your server.

Shay Nehmad
  • 1,103
  • 1
  • 12
  • 25
  • before use new tools (tmux..), I would like understand why the "native" way doesn't work :) I don't understand your first sentence : "you use the same shell for which the configuration exists", I connect to the userA with ssh to computer A, with the userA from the computer A I can use all alias/functions without any problem. I reload (source..) basrh files in the order I describe in my initial post – spacecodeur Aug 30 '16 at 06:38
  • You might be ssh-ing into zsh or something – Shay Nehmad Aug 30 '16 at 06:43