1

Basically i would like to have a global alias from my WSL that applies to the remote machine even without putting my local .profile to the remote machines.

example:

WSL on local machine

alias command1

remote machine via ssh

blank .profile but still accepts command1 from local WSL

I would like to know if this is possible?

1
  • Welcome on SuperUser. Try to focus on your question. edit your post to make it more clear. Usually your problem is clear in your mind, but not yet in the readers' one. :-). Give it a look the to How to Ask page. For example I cannot still understand (maybe it is me) if you want to have on the local machine an alias to execute a command on the remote machine, or if you want to have the same alias on the local and the remote machine. BTW you have an answer below. Comment it and give it a look there too. – Hastur Jun 15 '20 at 20:49
1

One of the ways...

Consider that different machines may need different paths and may have different shell (bash, dash, sh, csh, tcsh, zsh...) and the command/alias of one can be not adequate or understandable for the others.

It is already a good practice to have a .bash_aliases file in which to put your commands and to copy that file on the remote machines, but it seems to be what you do not want to do :-)

So you can think to something like to put your alias or the commands you want to execute in a file (e.g. remote-box-commands.bash) then to do on the local machine

cat remote-box-commands.bash | ssh user@remoteserver

and in the file remote-box-commands.bash you put something like

#Put here your ~/.profile  # or the command you want to execute remotely
/bin/bash                  # or whatever shell you will use.

You should complete with the proper options.
For the help on whatever command use man whatever or help whatever (if internal of the shell).

Read more for examples here

6
  • Your example looks like it will simply run source .profile on the remote machine. How does that address the question's requirement of loading the local profile? – Bob Jun 15 '20 at 19:02
  • I wrote too fast... There was an error but the remote-box-commands.bash file is local, printed by cat to the stdout piped to ssh and executed on the remote machine. – Hastur Jun 15 '20 at 20:39
  • thanks for the very fast reply. i think this would work. although i might need to setup more things when doing ssh on 2 levels of servers e.g. local(wsl) > connect to server1 > from server1 ssh to server2 – Roo-Gi Jun 15 '20 at 21:00
  • You are welcome. If you set up the remote machine via ssh authorized_keys you do not need to write passwords. To copy a file you only need scp localfile remoteserver:directory/where/you/want (here I suppose the same username else you have to write remoteuser@remoteserver). It works bash autocomplete and it becomes simple as to manage file locally. – Hastur Jun 15 '20 at 22:08
  • by the way, i tried this using ssh with passphrase and it just closes the connection afterwards. – Roo-Gi Jun 16 '20 at 20:33

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.