Google1, google2, google3, …, apple1, apple2, apple3Īll those hosts might have completely different settings even different ports and you simply need to $ ssh c1 You could for example use a naming convention for clouded vs. Wouldn’t it be much more simple to define everything into a file and don’t care about the rest anymore? Each of them is having different login options such as: some still use passwords, others use rsa keys, others ed25519 keys, lots of different initial users to use for the connection and much more. Imagine you have a couple of dozens or even hundred servers you have to take care of. The final connection string that will be made internally will look like this: ssh -p 10022 -i -o PubkeyAuthentication=yes -o ServerAliveInterval=30 So from that you must always remember that whenever a specific value has been found, it cannot be overwritten by values defined below. Use ServerAliveInterval as there is no previous definition.Don’t use PubkeyAuthentication as it has already been defined for this connection in c*.Don’t use Port as it has already been defined for this connection in c*.Don’t use User as it has already been defined for this connection in c*.Find more general section Host c* and use their values (User, Port, etc).Find section Host c1 and use its corresponding HostName (192.168.0.1).Notice here that the general definitions are at the very top and more wildcarded definitions (using the asterisk *) are followed below. The important part to keep track of is the Host section (aligned to the left). Let’s restructure the ~/.ssh/config into the right order and check the resulting connection string: Host c1 Now this is totally not what you intended to do! Right way The final connection string that will be made internally will look like this: ssh -p 22 -i -o PubkeyAuthentication=no -o ServerAliveInterval=30 Ignore PubkeyAuthentication (already defined above).If you want to ssh connect to c1 ( ssh c1), the file is read as follows: Let’s do this for a second and see what the outcoming ssh connection string will be: Host * No, what many people do wrong is to define the general stuff at the top. Let’s define a basic ~/.ssh/config containing the examples above and see what it does: Wrong way General section (which applies to all).Some generalization (with wildcard definitions).You can basically categorize blocks into three stages: Probably the most important part which is widely overlooked is the order of definition blocks in ~/.ssh/config and accordingly /etc/ssh/ssh_config in terms of generalization and specialization.
0 Comments
Leave a Reply. |