ssh_config文件配置实例

根据《OpenSSH——ssh_config》的介绍,这里做几个关于ssh_config文件配置的练习。

一、环境设定

1、假定使用ssh_config文件中的“~/.ssh/config”文件
2、现在有服务器A,B和C,这3台服务器上都运行SSH Server
3、A,B,C的域名分别为:“antix1.space.org,antix2.space.org,antix3.space.org”
4、A,B,C上SSH Server监听的端口号都为“1046”
5、本地机器上的SSH Client与A,B,C上的SSH Server建立SSH连接使用的账户都为“dsl”
6、本地机器上的SSH Client与A,B,C上的SSH Server建立SSH连接对应“dsl”账户的私钥文件都为“~/.ssh/dsl_private_key”

二、通过命令行方式与A,B,C上的SSH Server建立SSH连接

与A,B,C上的SSH Server建立SSH连接的命令分别如下所示:

ssh -i ~/.ssh/dsl_private_key -l dsl -p 1046 antix1.space.org
ssh -i ~/.ssh/dsl_private_key -l dsl -p 1046 antix2.space.org
ssh -i ~/.ssh/dsl_private_key -l dsl -p 1046 antix3.space.org

三、通过ssh_config文件配置方式与A,B,C上的SSH Server建立SSH连接(不使用通配符,转义序列等高级配置)

现在“~/.ssh/config”文件中配置有如下内容:

Host antix1  
    HostName antix1.space.org  
    User dsl  
    Port 1046  
    IdentityFile ~/.ssh/dsl_private_key  

Host antix2  
    HostName antix2.space.org  
    User dsl  
    Port 1046  
    IdentityFile ~/.ssh/dsl_private_key  

Host antix3  
    HostName antix3.space.org  
    User dsl  
    Port 1046  
    IdentityFile ~/.ssh/dsl_private_key  

与A,B,C上的SSH Server建立SSH连接的命令分别如下:

ssh antix1
ssh antix2
ssh antix3

四、通过ssh_config文件配置方式与A,B,C上的SSH Server建立SSH连接(使用通配符,转义序列等高级配置)

现在“~/.ssh/config”文件中配置有如下内容:

Host antix*  
    HostName %h.space.org  
    User dsl  
    Port 1046  
    IdentityFile ~/.ssh/dsl_private_key  

与A,B,C上的SSH Server建立SSH连接的命令分别如下:

ssh antix1
ssh antix2
ssh antix3

你可能感兴趣的:(ssh,实例,openssh)