Create shortcut log-in command: Difference between revisions
(Created page with "It can be very tedious to have to type full command to log into a remote machine using the secure shell (ssh) when a remote machine is used often. A simple solution is to add a c...") |
No edit summary |
||
(12 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
It can be very tedious to have to type full command to log into a remote machine using the secure shell (ssh) when a remote machine is used often. A simple solution is to add a custom command to the .basrc. Open the .bashrc (which is in the root of home directory) using any plain text editor. E.g.: | It can be very tedious to have to type full command to log into a remote machine using the secure shell (ssh) when a remote machine is used often. | ||
== Add a custom command to the .bashrc == | |||
A simple solution is to add a custom command to the .basrc. Open the .bashrc (which is in the root of home directory) using any plain text editor. E.g.: | |||
<source lang='bash'> | <source lang='bash'> | ||
vi $HOME/.bashrc | vi $HOME/.bashrc | ||
</source> | </source> | ||
Then, using the <code>alias</code> function, define a new function derived from the <code>ssh</code> command and your personal credentials: | |||
<source lang='bash'> | <source lang='bash'> | ||
alias lx7="ssh username@scomp1095.wurnet.nl" | alias lx7="ssh username@scomp1095.wurnet.nl" | ||
alias hpc="ssh username@ | alias hpc="ssh username@login.anunna.wur.nl" | ||
</source> | </source> | ||
The new function will be available from next login, therefore log out of the active terminal and log back in. From the freshly opened terminal, issuing the following command: | |||
<source lang='bash'> | <source lang='bash'> | ||
lx7 | lx7 | ||
</source> | </source> | ||
should give you direct access to <code>scomp1095</code>, for instance. If you do this in combination with a [[ssh_without_password | passwordless setup]], you will not even be prompted for a password. | |||
== Using a ssh config file == | |||
Instead of using the alias function, it is possible to use a ssh config file. The ssh config file can be found at $HOME/.ssh/config . | |||
If the ssh config file does not exist, you can create it with, e.g.,: | |||
<source lang='bash'> | |||
touch $HOME/.ssh.config | |||
</source> | |||
If the ssh config file exists, you can add the different options you use to log in of the different servers/clusters. For example, for Anunna, you can add: | |||
<source lang='bash'> | |||
Host hpc | |||
Hostname login.anunna.wur.nl | |||
User username | |||
IdentityFile PATH_TO_PRIVATE_KEY (if applicable) | |||
ForwardX11 yes (if applicable) | |||
</source> | |||
After the addition to the ssh congig file, you can log in as follows: | |||
<source lang='bash'> | |||
ssh hpc | |||
</source> | |||
You may add to the ssh config file several configurations for the same or several clusters. For example, for the two aliases in the section [[Add a custom command to the .bashrc | Add a custom command to the .bashrc ]], you can add the following lines to your ssh config file: | |||
<source lang='bash'> | |||
Host scomp | |||
HostName scomp1095.wurnet.nl | |||
User username | |||
Host hpc | |||
Hostname login.anunna.wur.nl | |||
User username | |||
</source> | |||
For more information on the possible different options for the ssh config file, you may consult the [http://linux.die.net/man/5/ssh_config man page]. | |||
== See also == | |||
* [[ssh_without_password | ssh without password]] | |||
* [[Lx6_and_Lx7_compute_nodes | Lx6 and Lx7 compute nodes]] | |||
* [[log_in_to_Anunna | Logging into cluster using ssh and file transfer]] | |||
== External links == |
Latest revision as of 15:00, 19 March 2019
It can be very tedious to have to type full command to log into a remote machine using the secure shell (ssh) when a remote machine is used often.
Add a custom command to the .bashrc
A simple solution is to add a custom command to the .basrc. Open the .bashrc (which is in the root of home directory) using any plain text editor. E.g.: <source lang='bash'> vi $HOME/.bashrc </source>
Then, using the alias
function, define a new function derived from the ssh
command and your personal credentials:
<source lang='bash'>
alias lx7="ssh username@scomp1095.wurnet.nl"
alias hpc="ssh username@login.anunna.wur.nl"
</source>
The new function will be available from next login, therefore log out of the active terminal and log back in. From the freshly opened terminal, issuing the following command:
<source lang='bash'>
lx7
</source>
should give you direct access to scomp1095
, for instance. If you do this in combination with a passwordless setup, you will not even be prompted for a password.
Using a ssh config file
Instead of using the alias function, it is possible to use a ssh config file. The ssh config file can be found at $HOME/.ssh/config . If the ssh config file does not exist, you can create it with, e.g.,: <source lang='bash'> touch $HOME/.ssh.config </source> If the ssh config file exists, you can add the different options you use to log in of the different servers/clusters. For example, for Anunna, you can add:
<source lang='bash'> Host hpc
Hostname login.anunna.wur.nl User username IdentityFile PATH_TO_PRIVATE_KEY (if applicable) ForwardX11 yes (if applicable)
</source>
After the addition to the ssh congig file, you can log in as follows: <source lang='bash'> ssh hpc </source>
You may add to the ssh config file several configurations for the same or several clusters. For example, for the two aliases in the section Add a custom command to the .bashrc , you can add the following lines to your ssh config file: <source lang='bash'> Host scomp
HostName scomp1095.wurnet.nl User username
Host hpc
Hostname login.anunna.wur.nl User username
</source>
For more information on the possible different options for the ssh config file, you may consult the man page.