1 Star 0 Fork 52

yimiaoxiehou / kasini3000

forked from chuanjiao10 / kasini3000 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
zkj_install_powershell_offline_win2linux_keyfile.ps1 2.12 KB
一键复制 编辑 原始数据 按行查看 历史
chuanjiao10 提交于 2022-04-02 23:22 . 更新:git库到2.35.1.2
#建议保存编码为:bom头 + utf8
#只支持用root权限,的ssh-key-file,安装powershell
param
(
[parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[Alias("ipaddress")][String]$目的ip地址,
[Alias("port")][uint16]$端口 = 22,
[String]$ssh_key_file_path = "${env:USERPROFILE}\.ssh\id_rsa",
[ValidateNotNullOrEmpty()]
[Alias("linux_powershell_files_path")][String]$linuxpowershell源文件目录 = 'c:\ProgramData\kasini3000\master_script\powershell-7.2-linux-x64\'
)
# & 'v-kai开启详细信息输出.ps1'
if ( ($IsWindows -eq $True) -or ($PSVersionTable.psversion.major -lt 6) ) #win
{
}
else
{
Write-Error "应该使用另一个脚本!"
exit 11
}
if (Test-Path -LiteralPath "${linux版powershell源文件目录}\pwsh")
{
}
else
{
Write-Error '错误:找不到powershell源文件目录,退出码 1'
exit 1
}
if (Test-Path -LiteralPath $ssh_key_file_path)
{
}
else
{
Write-Error '错误:找不到ssh_key_file_path,退出码 2'
exit 2
}
ssh.exe -i $ssh_key_file_path -p $端口 root@$目的ip地址 "rm -rf /opt/microsoft"
Start-Sleep 1
ssh.exe -i $ssh_key_file_path -p $端口 root@$目的ip地址 "mkdir -p '/opt/microsoft/powershell/7'"
Start-Sleep 1
$private:cmd = @"
lcd {0}
put -R . /opt/microsoft/powershell/7/
"@ -f $linuxpowershell源文件目录
$private:cmd | sftp.exe -i $ssh_key_file_path -P $端口 root@$目的ip地址 1>$null
Start-Sleep 2
#分离成单独的命令,报错比较清楚
ssh.exe -i $ssh_key_file_path -p $端口 root@$目的ip地址 "chmod -R 755 /opt/microsoft/powershell/7/pwsh"
ssh.exe -i $ssh_key_file_path -p $端口 root@$目的ip地址 "ln -s /opt/microsoft/powershell/7/pwsh /usr/bin/pwsh"
ssh.exe -i $ssh_key_file_path -p $端口 root@$目的ip地址 "echo '' >> /etc/ssh/sshd_config"
ssh.exe -i $ssh_key_file_path -p $端口 root@$目的ip地址 "echo 'Subsystem powershell /usr/bin/pwsh -sshs -NoLogo -NoProfile' >> /etc/ssh/sshd_config"
ssh.exe -i $ssh_key_file_path -p $端口 root@$目的ip地址 "echo 'UseDNS no' >> /etc/ssh/sshd_config"
Start-Sleep 1
ssh.exe -i $ssh_key_file_path -p $端口 root@$目的ip地址 "systemctl restart sshd.service"
exit 0
PowerShell
1
https://gitee.com/yimiaoCC/kasini3000.git
git@gitee.com:yimiaoCC/kasini3000.git
yimiaoCC
kasini3000
kasini3000
master

搜索帮助