touch ~/.ssh/config创建空的 SSH 配置文件

touch ~/.ssh/config

解释:

  • touch:这个命令会在指定的路径上创建一个空文件。如果文件已经存在,touch 会更新文件的最后修改时间。
  • ~/.ssh/config:这是 SSH 的配置文件路径。~ 表示当前用户的主目录,.ssh/config 是用于存放自定义 SSH 配置的文件。

创建或编辑 SSH 配置文件

  1. 通过 touch ~/.ssh/config 创建空的 SSH 配置文件(如果该文件不存在的话)。
  2. 然后,你可以使用文本编辑器(如 nano 或 vim)来编辑该配置文件。例如:

bashCopy Code

nano ~/.ssh/config

或者

bashCopy Code

vim ~/.ssh/config

配置文件的基本结构:

config 文件中,你可以为不同的主机(Host)设置不同的 SSH 选项。例如:

 

bashCopy Code

Host example-server HostName example.com User username Port 22 IdentityFile ~/.ssh/id_rsa

选项解释:

  • Host:这是你给主机起的别名,可以使用它来代替完整的域名或 IP 地址。
  • HostName:你连接的实际服务器地址或 IP 地址。
  • User:用于连接服务器的用户名。
  • Port:指定 SSH 连接使用的端口,默认是 22。
  • IdentityFile:指定私钥文件的路径,用于公钥认证。

配置示例:

如果你有多个服务器需要 SSH 连接,可以为每个服务器配置不同的条目。例如:

 

bashCopy Code

Host server1 HostName server1.example.com User user1 IdentityFile ~/.ssh/id_rsa_server1 Host server2 HostName server2.example.com User user2 IdentityFile ~/.ssh/id_rsa_server2

这将允许你通过以下命令方便地连接到这些服务器:

 

bashCopy Code

ssh server1 ssh server2

这样,SSH 会自动使用你为每个主机配置的参数(如用户名、私钥等)。

git@github.com$ ssh -T -vvv git@github.com OpenSSH_9.9p1, OpenSSL 3.2.4 11 Feb 2025 debug1: Reading configuration data /c/Users/SW0122/.ssh/config debug1: Reading configuration data /etc/ssh/ssh_config debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/c/Users/SW0122/.ssh/known_hosts' debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/c/Users/SW0122/.ssh/known_hosts2' debug2: resolving "github.com" port 22 debug3: resolve_host: lookup github.com:22 debug3: channel_clear_timeouts: clearing debug3: ssh_connect_direct: entering debug1: Connecting to github.com [20.205.243.166] port 22. debug3: set_sock_tos: set socket 4 IP_TOS 0x48 debug1: Connection established. debug1: identity file /c/Users/SW0122/.ssh/id_rsa type 0 debug1: identity file /c/Users/SW0122/.ssh/id_rsa-cert type -1 debug1: identity file /c/Users/SW0122/.ssh/id_ecdsa type -1 debug1: identity file /c/Users/SW0122/.ssh/id_ecdsa-cert type -1 debug1: identity file /c/Users/SW0122/.ssh/id_ecdsa_sk type -1 debug1: identity file /c/Users/SW0122/.ssh/id_ecdsa_sk-cert type -1 debug1: identity file /c/Users/SW0122/.ssh/id_ed25519 type -1 debug1: identity file /c/Users/SW0122/.ssh/id_ed25519-cert type -1 debug1: identity file /c/Users/SW0122/.ssh/id_ed25519_sk type -1 debug1: identity file /c/Users/SW0122/.ssh/id_ed25519_sk-cert type -1 debug1: identity file /c/Users/SW0122/.ssh/id_xmss type -1 debug1: identity file /c/Users/SW0122/.ssh/id_xmss-cert type -1 debug1: Local version string SSH-2.0-OpenSSH_9.9 debug1: Remote protocol version 2.0, remote software version 6fdec156f debug1: compat_banner: no match: 6fdec156f debug2: fd 4 setting O_NONBLOCK debug1: Authenticating to github.com:22 as 'git' debug3: record_hostkey: found key type ED25519 in file /c/Users/SW0122/.ssh/known_hosts:1 debug3: load_hostkeys_file: loaded 1 keys from github.com debug1: load_hostkeys: fopen /c/Users/SW0122/.ssh/known_hosts2: No such file or directory debug1: load_hostkeys: fopen /e: Permission denied (publickey).
04-03
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值