ssh
ssh 免密登录
私匙和公匙
- id_rsa:私匙
- id_rsa.pub:公匙
私匙和公匙文件默认目录
- windows:C:/User/
/.ssh - Linux:/home/
/.ssh
若无私匙和公匙文件,则使用ssh-keygey创建。
# 在默认目录下创建私匙和公匙文件
ssh-keygen -t rsa
# 将公匙拷贝到远程服务器
ssh-copy-id -p 18282 zkln@192.168.7.32
# 会将 `id_rsa.pub` 文件内容,复制到默认 ssh 配置文件目录 `authorized_keys` 文件中。
# authorized_keys 文件属性 `-rw-------`
附录
sh-keygen 命令说明
$ ssh-keygen -f C:\\Users\\ahxie\\.ssh\\github\\id_rsa -t rsa -C "ahxieqi@163.com"
# -f 生成的ssh保存的文件
# -t ssh 类型
# -C 备注
服务启动异常
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0777 for '/etc/ssh/ssh_host_rsa_key' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
key_load_private: bad permissions
Could not load host key: /etc/ssh/ssh_host_rsa_key
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0777 for '/etc/ssh/ssh_host_dsa_key' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
key_load_private: bad permissions
Could not load host key: /etc/ssh/ssh_host_dsa_key
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0777 for '/etc/ssh/ssh_host_ecdsa_key' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
key_load_private: bad permissions
Could not load host key: /etc/ssh/ssh_host_ecdsa_key
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0777 for '/etc/ssh/ssh_host_ed25519_key' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
key_load_private: bad permissions
Could not load host key: /etc/ssh/ssh_host_ed25519_key
/var/run/sshd must be owned by root and not group or world-writable.
解决方法:
chmod 600 /etc/ssh/ssh_host_rsa_key /etc/ssh/ssh_host_dsa_key /etc/ssh/ssh_host_ecdsa_key /etc/ssh/ssh_host_ed25519_key
chmod 744 /var/run/sshd
ssh 不使用代理
- 本地网段:
192.168.6.x - 远程网段:
192.168.7.x - 本地已开启系统代理
需求:希望远程走物理网卡,而不是虚拟网卡
以管理员身份 powershell
-
查看网卡接口编号
# 物理网卡为 以太网 则对应 Idx 是 12 netsh interface ipv4 show interfaces # Idx Met MTU 状态 名称 # 12 25 1500 connected 以太网 # 66 5 1500 connected proxy -
添加临时路由:整个 192.168.7.x 网段
# 访问 192.168.7.0/24 网段时,通过网关 192.168.6.1 转发并强制从物理“以太网”接口出去 route add 192.168.7.0 mask 255.255.255.0 192.168.6.1 metric 1 IF <以太网Idx> -
测试验证
# 验证是否已经绕过代理 proxy Find-NetRoute -RemoteIPAddress 192.168.7.200 | Format-List # 正确结果能看到如下信息 # DestinationPrefix : 192.168.7.0/24 # InterfaceAlias : 以太网 # NextHop : 192.168.6.1 # RouteMetric : 1 # 测试端口 Test-NetConnection 192.168.7.200 -Port 22 -InformationLevel Detailed # 正确结果能看到如下信息 # InterfaceAlias : 以太网 # SourceAddress : 192.168.6.76 # NetRoute NextHop : 192.168.6.1 # TcpTestSucceeded : True重点看这几项:
InterfaceAlias 是否为 以太网 SourceAddress 是否为 192.168.6.76 NextHop 是否为 192.168.6.1 -
添加永久路由。临时路由重启后会失效,确认测试成功后,添加永久路由。
route -p add 192.168.7.0 mask 255.255.255.0 192.168.6.1 metric 1 IF <以太网Idx> -
删除临时或永久路由
route delete 192.168.7.0