Open several ssh terminals at once: Difference between revisions

From Sea of Fate
Jump to navigationJump to search
No edit summary
No edit summary
 
Line 4: Line 4:
==The First version==
==The First version==


===Code===
Open a text file with the ext of .sh
Open a text file with the ext of .sh
  nano ./open_prod_terminals.sh
  nano ./open_prod_terminals.sh
Copy the following into the file.
Copy the following into the file.
  #!/bin/bash
  #!/bin/bash
 
#
  # Open SSH sessions in separate terminal windows
  # Open SSH sessions in separate terminal windows
  gnome-terminal --tab --title="logan" -- bash -c "ssh logan; exec bash"
  gnome-terminal --tab --title="logan" -- bash -c "ssh logan; exec bash"
  gnome-terminal --tab --title="fig" -- bash -c "ssh fig; exec bash"
  gnome-terminal --tab --title="fig" -- bash -c "ssh fig; exec bash"
  gnome-terminal --tab --title="mandarin" -- bash -c "ssh mandarin; exec bash"
  gnome-terminal --tab --title="mandarin" -- bash -c "ssh mandarin; exec bash"
#
exit 0
Save and exit. Next we have to make it executable.
chmod +x ./open_prod_terminals.sh
From now we can use ./open_prod_terminals.sh to open several terminals at once.
===create an alias===


  exit 0
The text is a bit long and i will not want to type out the whole thing so instead we will create an alias of ./open_prod_terminals.sh. To do this open the shell configuration file
  nano ~/.bashrc
Scroll down to the bottom and add the line
alias sshp='./open_prod_terminals.sh' # alias to open production host ssh all at once
Save and exit. to reload the .bashrc so the alias is available immediately we need to "source" it.
source ~/.bashrc
Now type sshp to open a SSH session to the Production terminals.

Latest revision as of 18:59, 28 February 2025

Introduction

Continuing the theme of Random stuff and more particularly of Code Snippets and Linux Bash & Shell. This is how to open several terminals at once.

The First version

Code

Open a text file with the ext of .sh

nano ./open_prod_terminals.sh

Copy the following into the file.

#!/bin/bash
#
# Open SSH sessions in separate terminal windows
gnome-terminal --tab --title="logan" -- bash -c "ssh logan; exec bash"
gnome-terminal --tab --title="fig" -- bash -c "ssh fig; exec bash"
gnome-terminal --tab --title="mandarin" -- bash -c "ssh mandarin; exec bash"
#
exit 0

Save and exit. Next we have to make it executable.

chmod +x ./open_prod_terminals.sh

From now we can use ./open_prod_terminals.sh to open several terminals at once.

create an alias

The text is a bit long and i will not want to type out the whole thing so instead we will create an alias of ./open_prod_terminals.sh. To do this open the shell configuration file

nano ~/.bashrc

Scroll down to the bottom and add the line

alias sshp='./open_prod_terminals.sh' # alias to open production host ssh all at once 

Save and exit. to reload the .bashrc so the alias is available immediately we need to "source" it.

source ~/.bashrc

Now type sshp to open a SSH session to the Production terminals.