终端代理设置(windows,linux)

终端代理设置,win11开启OpenSSH

win11开启OpenSSH

  1. 打开“设置”,选择“应用”>“应用和功能”,然后选择“可选功能” 。
  2. 扫描列表,查看是否已安装 OpenSSH。 如果未安装,请在页面顶部选择“添加功能”,然后:
  3. 查找“OpenSSH 客户端”,再单击“安装”
  4. 查找“OpenSSH 服务器”,再单击“安装”

修改sshd配置C:\ProgramData\ssh如下

# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented. Uncommented options override the
# default value.

#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

#HostKey __PROGRAMDATA__/ssh/ssh_host_rsa_key
#HostKey __PROGRAMDATA__/ssh/ssh_host_dsa_key
#HostKey __PROGRAMDATA__/ssh/ssh_host_ecdsa_key
#HostKey __PROGRAMDATA__/ssh/ssh_host_ed25519_key

# Ciphers and keying
#RekeyLimit default none

# Logging
#SyslogFacility AUTH
#LogLevel INFO

# Authentication:

#LoginGraceTime 2m

RSAAuthentication yes
PubkeyAuthentication yes
PermitRootLogin yes

#PermitRootLogin prohibit-password
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

#PubkeyAuthentication yes

# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
# but this is overridden so installations will only check .ssh/authorized_keys
AuthorizedKeysFile .ssh/authorized_keys

#AuthorizedPrincipalsFile none

# For this to work you will also need host keys in %programData%/ssh/ssh_known_hosts
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes

# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
#PermitEmptyPasswords no

# GSSAPI options
#GSSAPIAuthentication no

#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
#PermitTTY yes
#PrintMotd yes
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
#PermitUserEnvironment no
#ClientAliveInterval 0
#ClientAliveCountMax 3
#UseDNS no
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none

# no default banner path
#Banner none

# override default of no subsystems
Subsystem sftp sftp-server.exe

# Example of overriding settings on a per-user basis
#Match User anoncvs
# AllowTcpForwarding no
# PermitTTY no
# ForceCommand cvs server

Match Group administrators
AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys

复制需要免密登录的公钥到C:\ProgramData\ssh 文件夹下,还要改名成 administrators_authorized_keys

cat id_rsa.pub >> administrators_authorized_keys

启动sshd服务

# Start the sshd service
Start-Service sshd

# OPTIONAL but recommended:
Set-Service -Name sshd -StartupType 'Automatic'

# Confirm the Firewall rule is configured. It should be created automatically by setup. Run the following to verify
if (!(Get-NetFirewallRule -Name "OpenSSH-Server-In-TCP" -ErrorAction SilentlyContinue | Select-Object Name, Enabled)) {
Write-Output "Firewall Rule 'OpenSSH-Server-In-TCP' does not exist, creating it..."
New-NetFirewallRule -Name 'OpenSSH-Server-In-TCP' -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
} else {
Write-Output "Firewall rule 'OpenSSH-Server-In-TCP' has been created and exists."
}

windows cmd

set http_proxy = "http://127.0.0.1:1189"
set http_proxy_user=
set http_proxy_pass=

powershell

启动配置文件为 $HOME\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

$env:all_proxy="socks5://127.0.0.1:10808"
$env:http_proxy_user=
$env:http_proxy_pass=

powershell设置脚本策略

启动 Windows PowerShell 时,执行策略是默认的Restricted > Restricted 执行策略不允许任何脚本运行。  AllSigned 和 RemoteSigned 执行策略可防止 Windows PowerShell 运行没有数字签名的脚本。本主题说明如何运行所选未签名脚本(即使在执行策略为 RemoteSigned 的情况下),还说明如何对  脚本进行签名以便您自己使用。有关 Windows PowerShell 执行策略的详细信息,请参阅 about_Execution_Policy。

get-executionpolicy #获取当前
set-executionpolicy remotesigned #设置策略可运行脚本.管理员身份

powershell添加sudo,可写入启动配置文件

function _sudo {
$ss = "$args ; pause"
Start-Process powershell -Verb runAs -ArgumentList $ss
}
set-alias -name sudo -value _sudo #添加sudo命令

Linux终端代理设置方法

启动配置文件为 $HOME\.bash_profile

set all_proxy = "socks5://127.0.0.1:10808"
set all_proxy_user=
set all_proxy_pass=

如果要查看是否生效,可以运行curl ip.gs或者curl cip.cc或者curl ifconfig.me,即可查看当前主机ip

也可以使用proxychains工具apt-get install proxychains

ProxyChains 的配置文件位于 /etc/proxychains.conf ,打开后你需要在末尾添加你使用的代理。

[ProxyList]
# add proxy here ...
# meanwile
# defaults set to "tor"
#socks4 127.0.0.1 9050

# example
socks5 127.0.0.1 8888

ProxyChains 的使用方式非常简单,直接在应用程序前加上 proxychains 即可

proxychains git clone https://github.com/rofl0r/proxychains-ng