How can I create an alias for multiple SSH commands?
Asked by
faint_signal_
I'm new to bash commands and using the terminal and I have a bit of a problem. To access my data files, I usually have to enter an SSH command, input a password, execute another SSH command, and then enter the password again. My terminal times out frequently, and it's really tiring to keep typing all that out. Is there any way to create an alias that combines these commands into one? I'd really appreciate any tips!
Answers
If you're on PowerShell, you can set up aliases in your profile script located at `$env:UserProfileDocumentsWindowsPowerShellMicrosoft.PowerShell_profile.ps1`. This saves a ton of time!
Reply to this answer
Absolutely! Just search for 'SSH alias or function' online for some good examples to follow.
Reply to this answer
You can set up a function in your profile file to simplify those commands. This way, you won't have to type everything every time you want to access your files.
Reply to this answer
Consider using SSH Agent and public key authentication. This method doesn't require entering your password multiple times, making it a lot more efficient!
Reply to this answer
Reply to this answer
Just to clarify, are you connecting to one server and then jumping to another? If that's the case, you can use `ssh -J first second` to make it all happen in one command! And if you can use SSH keys, you won't need to worry about passwords at all. You can configure specific options in `$env:userprofile/.ssh/config`, allowing you to just type `ssh files` after setting it up.
Reply to this answer
Add your answer
Answers are reviewed before publication.
Related Discussions