Jul 28 2008

ssh连接时候的per-user独立用户配置

Category: 技术ssmax @ 16:38:30

很多脚本命令没有考虑到ssh连接时候的端口啊,用户名等问题,这个可以通过设置个人的ssh配置文件来轻松解决,个人配置文件应该放在 ~/.ssh/config ,没有的话就新建一个并且chmod 600 ~/.ssh/config

基本里面的配置可以看 man ssh_config

主要就是分开每个Host

比如 :

Host ip1

       HostName hostname1

       Port port1

       User user1

Host ip2

       HostName hostname2

       Port port2

       User user2

这样直接ssh连接这个ip1的时候,就自动找好端口和用户名了,还有其他配置详细看看man

Name

ssh_config – OpenSSH SSH client configuration files

Synopsis

~/.ssh/config

/etc/ssh/ssh_config

Description

ssh obtains configuration data from the following sources in the following order:

1. command-line options

2. user’s configuration file (~/.ssh/config)
3. system-wide configuration file (/etc/ssh/ssh_config)For each parameter, the first obtained value will be used. The configuration files contain sections separated by ”Host” specifications, and that section is only applied for hosts that match one of the patterns given in the specification. The matched host name is the one given on the command line.Since the first obtained value for each parameter is used, more host-specific declarations should be given near the beginning of the file, and general defaults at the end.

The configuration file has the following format:

Empty lines and lines starting with ‘#’ are comments.

Otherwise a line is of the format ”keyword arguments”. Configuration options may be separated by whitespace or optional whitespace and exactly one ‘=’; the latter format is useful to avoid the need to quote whitespace when specifying configuration options using the ssh, scp and sftp -o option.

The possible keywords and their meanings are as follows (note that keywords are case-insensitive and arguments are case-sensitive):

Host‘ Restricts the following declarations (up to the next Host keyword) to be only for those hosts that match one of the patterns given after the keyword. ‘*’ and ‘?’ can be used as wildcards in the patterns. A single ‘*’ as a pattern can be used to provide global defaults for all hosts. The host is the hostname argument given on the command line (i.e., the name is not converted to a canonicalized host name before matching).

等等。。。