Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ssh config file
06-06-2018, 11:16 AM (This post was last modified: 06-11-2018 07:10 PM by cchen.)
Post: #1
ssh config file
config file is a very handy way to specify all the usernames, remote addresses, command line options etc. It saves your time by preventing you from specifying all the information every time.
Here is an example of config file that is used in hututa:
Code:
Drive example:

Host git.baijia.info
Port 22111
User git


Put the frequently accessed remote addresses information in config file, then you don't have to remember all the details.

Here are some useful cases of config usage:

P1). connecting to limbo1 from tb20

Using the command, we need to remember the ip address. Furthermore, everyday we will be banned from accessing it since the key changes everyday, and strict key checking is enforced. We can simply add the following lines in ~/.ssh/config file to solve the problem:
Code:
Host <alias-for-hostname>
  HostName 10.6.10.20
  User root
  StrictHostKeyChecking no

Notice that you can ignore the "User root" line if you have your own account instead of using the root to access limbo1.

use "bash" command to refresh the bash, then you can simply use "ssh <alias-for-hostname>" in future usage

P2). To connect to TBG20
I think it is a good idea to add an alias for this command in .ssh/config file so that we don't need to remember the hostname and port number. The syntax to add alias is:
Code:
Host <alias for hostname>
  HostName <ip addr>
  Port <port#>
use "bash" command to refresh the bash, then we can simply use "ssh <alias for hostname>" in the future usage

Note that the default value for 'User" is the current user name on your machine (i.e., the $USER value). If you need to use a different username, remember to specify it in the config file

*An example of config file that you may find useful:
Code:
Drive example: ~.ssh/config

Host codb2.dthink.net
User git
IdentityFile ~/.ssh/key_cchen

Host codb3.zettadom.com
Port 13122
User gito
IdentityFile ~/.ssh/key_cchen

Host codb3.datathinking.org
Port 13122
User gito
IdentityFile ~/.ssh/key_cchen

Host codb4.d-thinker.org
Port 2822
User git
IdentityFile ~/.ssh/key_cchen

Host cb8.hututa.cn
Port 18022
User gito
IdentityFile ~/.ssh/key_cchen

Host codb.hututa.com
Port 12322
User git
IdentityFile ~/.ssh/key_cchen

Host trajan.d-thinker.org
Port 22
User git
IdentityFile ~/.ssh/key_cchen

Host git.baijia.info
Port 22111
User git

Host tb20
  HostName ada.zettadom.com
  Port 30022
  User cchen

Host tb15
  HostName wretar.dthink.net
  Port 22108
  User cchen

Host otter
  HostName 192.168.1.107
  User cchen

Host otter
  HostName 192.168.1.107
  User cchen

After adding the config file under .ssh folder (notice that you may need to create the .ssh folder if it doesn't exist), remember to grant permission for user to read and write. The code is:
Code:
chmod 600 ~/.ssh/config
It is also suggested to use the following command to make sure that you (user) is the owner
Code:
chown $USER ~/.ssh/config

Notice that you need to have rw permission for user ONLY, that is, others should not have the permission for it.

check carefully the specifications stated in the file, make sure the information is all correct. Then reboot the bash so that it can work.

RR rayluk
Find all posts by this user
Quote this message in a reply
06-06-2018, 11:21 AM
Post: #2
RE: ssh config file
(06-06-2018 11:16 AM)cchen Wrote:  After adding the config file under .ssh folder, it is very important not only to grant permission for user to read and write, it is also important to specify the owner for it. The code is:
Code:
chmod 600 ~/.ssh/config
chown $USER ~/.ssh/config
Notice that you need to have rw permission for user ONLY.

Also check the identity file path specification, make sure it's the correct path to private key.

RR rayluk

Please place it under a proper board. Technology is too general. I remember there is a board for ssh. Please move this to the board first.
Find all posts by this user
Quote this message in a reply
06-06-2018, 03:41 PM
Post: #3
RE: ssh config file
config file is a very handy way to specify all the usernames, remote addresses, command line options etc. It saves your time by preventing you from specifying all the information every time.

After adding the config file under .ssh folder, remember to grant permission for user to read and write, as well as to specify the owner for it as user. The code is:
Code:
chmod 600 ~/.ssh/config
chown $USER ~/.ssh/config
Notice that you need to have rw permission for user ONLY, that is, others should not have the permission for it.

check carefully the specifications stated in the file, make sure the information is all correct. Then reboot the bash so that it can work.

RR rayluk
Find all posts by this user
Quote this message in a reply
06-06-2018, 05:21 PM
Post: #4
RE: ssh config file
(06-06-2018 03:41 PM)cchen Wrote:  config file is a very handy way to specify all the usernames, remote addresses, command line options etc. It saves your time by preventing you from specifying all the information every time.

After adding the config file under .ssh folder, remember to grant permission for user to read and write, as well as to specify the owner for it as user. The code is:
Code:
chmod 600 ~/.ssh/config
chown $USER ~/.ssh/config
Notice that you need to have rw permission for user ONLY, that is, others should not have the permission for it.

check carefully the specifications stated in the file, make sure the information is all correct. Then reboot the bash so that it can work.

RR rayluk

LGTM.
`chown $USER ~/.ssh/config` may not be always need but its good to have it here.

Please also add an example of the ssh configuration file to the head post so readers can understand it more clearly.
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump: