项目发布用的是jenkins,不管是python,scala,php,vue都能够简单通过jenkins部署。但是公司部分项目用的.net,跑在windows下面,也需要接入jenkins。就比较麻烦了。
第一种想法:在linux下,用mono,nuget,msbuild等对.net进行编译,然后通过ftp工具传到windows上面。但是在打包.net项目时,各种缺包。最后放弃了。
第二种想法:linux ssh到windows,触发一下脚本,通过脚本进行打包发布。那前提条件是,linux 能ssh到windows。这也本文件重点了。
一,linux ssh windows 密码方式
1,下载openssh,解压至C:\OpenSSH-Win64
下载地址:https://github.com/PowerShell/Win32-OpenSSH/releases
v7.9.0.0p1-Beta是一个分界点。建议安装v7.9.0.0p1-Beta以后版本,本文用的openssh是v8.1.0.0p1-Beta
2,将C:\OpenSSH-Win64加到环境变量Path,该步骤可以不做。
3,打开cmd,进入C:\OpenSSH-Win64(解压目录),执行命令:
powershell.exe -ExecutionPolicy Bypass -File install-sshd.ps1
4,启动sshd,并设置自启动
net start sshd sc config sshd start=auto
5,windows防火墙开放22端口,这一步很容易忽视
6,linux ssh 到windows测试
二,linux ssh windows 密钥方式
1,修改sshd_config
# 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 #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 #AuthorizedKeysFile %programdata%/ssh/administrators_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 no 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目录下,ProgramData是个隐藏文件夹。
2,在用户根目录下创建.ssh/authorized_keys,并授权
把.pub(公钥文件)中的内容copy到.ssh/authorized_keys中,然后执行以下命令
icacls authorized_keys /inheritance:r icacls authorized_keys /grant SYSTEM:(F) icacls authorized_keys /grant BUILTIN\Administrators:(F) net stop sshd //关闭 net start sshd //启动
3,测试linux ssh windows密钥登录
转载请注明
作者:海底苍鹰
地址:http://blog.51yip.com/server/2372.html
大佬你好,请教个问题,我也用的windows openssh, 有什么方法能实现有用户登录SSH就发送邮件提醒呢,Google搜了很久没找到方法,都是针对linux的