arkanon

Windows Subsystem Linux

Jul 29th, 2018
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 9.94 KB | None | 0 0
  1. # >> Windows Subsystem Linux <<
  2.  
  3. # <http://thewindowsclub.com/windows-10-installation-upgrade-errors>
  4.  
  5. # >> Windows 10 Insider Preview <<
  6. #   <http://microsoft.com/en-us/software-download/windowsinsiderpreviewadvanced>
  7.  
  8. # >> Windows Server 2016 Insider Preview <<
  9. #   <http://microsoft.com/en-us/software-download/windowsinsiderpreviewserver>
  10. #
  11. #   <http://msdn.microsoft.com/en-us/commandline/wsl/install-on-server>
  12. #   <http://insider.windows.com/pt-br/for-business/>
  13.  
  14. #   <http://stackoverflow.com/questions/40033608/enable-windows-10-developer-mode-programmatically>
  15. #   <http://docs.microsoft.com/en-us/windows/wsl/install-win10>
  16.  
  17.      # cmd
  18.      dir     # mostra o espaço livre
  19.      powershell
  20.  
  21.      # powershell
  22.      systeminfo | Select-String "^OS Name","^OS Version"
  23.  
  24.          get-windowsFeature                              *linux
  25.      install-windowsFeature         -restart             *linux
  26.          get-windowsOptionalFeature -online -featureName *linux
  27.       enable-WindowsOptionalFeature -online -featureName *linux -all -limitAccess -noRestart
  28.  
  29.      invoke-webRequest -uri https://aka.ms/wsl-ubuntu-1604 -outFile ubuntu.zip -useBasicParsing
  30.      expand-archive ubuntu.zip ubuntu
  31.      cd ubuntu
  32.      ls
  33.      ubuntu.exe
  34.  
  35.  
  36.  
  37. # reset the Password in Linux Bash in Windows <http://askubuntu.com/a/808425>
  38. #
  39. # entrar no linux subsystem como root
  40.   lxrun /setdefaultuser root
  41.  
  42.  
  43.  
  44.   cd %localappdata%\lxss
  45.   dir
  46.  
  47.   cat /etc/lsb-release
  48.  
  49.   export    DISPLAY=:0
  50.   export TIMEFORMAT=%lR
  51.  
  52.   sudo -Si
  53.  
  54.   passwd
  55.  
  56.   scp -p arkanon@hulk:.ssh/id_rsa.pub ~/.ssh
  57.   cat ~/.ssh/id_rsa.pub >| ~/.ssh/authorized_keys
  58.   rm  ~/.ssh/id_rsa.pub
  59.   chmod 600 ~/.ssh/authorized_keys
  60.   scp -p arkanon@hulk:/etc/apt/sources.list.d/* /etc/apt/sources.list.d
  61.  
  62.   sedc="
  63.         s/[ \t]*#[ \t]*(deb )/\1/    # descomenta linhas de repositórios adicionais
  64.         s/[ \t]*(deb-src |#).*//     # limpa linhas com [deb-src ] e remove comentarios
  65.         /^$/d                        # deleta linhas em branco
  66.         s|br\.(archive)|\1|          # troca do repositorio brasileiro para o oficial
  67.       "
  68.   sed -ri "$sedc" /etc/apt/sources.list
  69.  
  70.   time apt-key adv --keyserver keyserver.ubuntu.com --recv-keys $( apt update 2>&1 | grep -oP '( NO_PUBKEY \K[^ ]+)+' | sort -u )
  71.  
  72.   time do-release-upgrade -f DistUpgradeViewNonInteractive -d
  73.   apt-get install -f
  74.   dpkg --configure -a
  75.   apt -y install console-common
  76. # apt -y install openssh-server
  77.   apt -y install synaptic apt-xapian-index
  78.   apt -y install vim vim-gtk3 vim-gtk3-py2 exuberant-ctags
  79.   update-apt-xapian-index # <http://superuser.com/a/1132327>
  80.   synaptic
  81.  
  82.   # >> atualização <<
  83.   (
  84.     apt -y remove vim-tiny
  85.     time apt update
  86.     apt list --upgradable
  87.     time apt -y full-upgrade
  88.   )
  89.  
  90.   # >> limpeza <<
  91.   (
  92.     du -chs /var/cache/apt/archives/
  93.     apt -y autoremove || apt-get -y autoremove
  94.     dpkg --purge $(dpkg --get-selections | grep deinstall | cut -f1)
  95.     apt clean || rm /var/cache/apt/archives/*.deb
  96.     du -chs /var/cache/apt/archives/
  97.   )
  98.  
  99. scp administrador@hulk:/fs/etc/profile.d/bash-basic.sh /etc/profile.d/bash-basic.sh
  100.  
  101. cat << \EOT >| /etc/profile.d/wsl.sh
  102. # /etc/profile.d/wsl.sh
  103.  
  104. # Arkanon <arkanon@lsd.org.br>
  105. # 2017/09/19 (Tue) 14:59:41 BRT
  106. # 2017/09/19 (Ter) 09:27:02 BRT
  107.  
  108.   export DISPLAY=${DISPLAY:-:0}
  109.  
  110.             PATH=$PATH:/mnt/c/Windows
  111.             PATH=$PATH:/mnt/c/Windows/System32
  112.             PATH=$PATH:/mnt/c/Windows/System32/WindowsPowerShell/v1.0
  113.             PATH=$PATH:/mnt/c/WINDOWS/System32/Wbem
  114.             PATH=$PATH:/mnt/c/Windows/SysWOW64
  115.             PATH=$PATH:/mnt/c/Windows/SysWOW64/WindowsPowerShell/v1.0
  116.             PATH=$PATH:/mnt/c/WINDOWS/SysWOW64/Wbem
  117.             PATH=$PATH:/mnt/c/ProgramData/chocolatey/bin
  118.             PATH=$PATH:/mnt/c/Program\ Files/OpenSSH-Win64
  119.             PATH=$PATH:/mnt/c/Program\ Files/SysInternals
  120.             PATH=$PATH:/mnt/c/Users/${USER^}/AppData/Local/Microsoft/WindowsApps
  121.   export    PATH
  122.  
  123. # EOF
  124. EOT
  125.  
  126. chmod 755 /etc/profile.d/bash-basic.sh
  127. chmod 755 /etc/profile.d/wsl.sh
  128.  
  129. ln -fs ~/.bashrc .profile
  130.  
  131. cat << \EOT >| ~/.profile
  132. # ~/.profile
  133.  
  134. # Arkanon <arkanon@lsd.org.br>
  135. # 2017/09/19 (Ter) 09:29:49 BRT
  136. # 2017/05/29 (Mon) 14:50:45 BRT
  137. # 2017/04/24 (Mon) 23:23:12 BRS
  138. # 2017/01/10 (Tue) 08:26:02 BRD
  139. # 2017/01/09 (Mon) 16:03:58 BRD
  140. # 2016/11/28 (Seg) 14:36:24 BRD
  141. # 2016/08/23 (Ter) 14:03:07 BRS
  142. # 2016/06/10 (Sex) 11:45:23 BRS
  143. # 2016/04/19 (Ter) 08:37:27 BRS
  144.  
  145.   export     AD_CRED=$HOME/.crd
  146.   export    VPN_CRED=$AD_CRED
  147.   export  RDESK_CRED=$AD_CRED
  148.   export PSEXEC_CRED=$AD_CRED
  149.  
  150.   export    VIMSIGN1='Name <user@domain>'
  151.   export    VIMSIGN2='Name <user@domain>'
  152.   export  LC_COLLATE="C"
  153. # export LC_MESSAGES="C"
  154.  
  155. # export  HTTP_PROXY="http://fortigate.lsd.org.br:1000"
  156. # export  HTTP_PROXY="http://wpad.lsd.org.br/wpad.dat"
  157.   export  http_proxy="$HTTP_PROXY"
  158.  
  159.   export HTTPS_PROXY="$HTTP_PROXY"
  160.   export https_proxy="$HTTP_PROXY"
  161.  
  162. # EOF
  163. EOT
  164.  
  165. sudo visudo
  166. # %sudo ALL=(ALL)  NOPASSWD: /usr/sbin/sshd -D
  167. # %sudo ALL=(ALL)  NOPASSWD: /usr/sbin/synaptic
  168. # %sudo ALL=(ALL)  NOPASSWD: /usr/sbin/visudo
  169. # %sudo ALL=(ALL)  NOPASSWD: /usr/bin/apt
  170. # %sudo ALL=(ALL)  NOPASSWD: /usr/bin/apt-get
  171. # ALL   ALL=(root) NOPASSWD: /usr/sbin/service
  172.  
  173. scp administrador@hulk:/fs/etc/vim/vimrc-basic /etc/vim/vimrc.local
  174. chmod 644 /etc/vim/vimrc.local
  175.  
  176. # <http://noise.paulos.cz/post/windows10-14352-ssh-server/>
  177. HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Ssh\Broker\DevToolsUser
  178.  
  179. <cmd>+<r>shell:startup
  180. <cmd>+<r>%appdata%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar
  181. <cmd>+<r>%appdata%\..\Local\Microsoft\Windows\WinX\Group3
  182.  
  183.  
  184.  
  185. # >> openssh-server <<
  186. vi /etc/ssh/sshd_config
  187. # Port 22
  188. # ListenAddress 0.0.0.0
  189. # PermitRootLogin yes
  190. # PasswordAuthentication yes
  191. # ChallengeResponseAuthentication yes
  192. # X11Forwarding yes
  193. # UsePrivilegeSeparation no
  194. # KbdInteractiveAuthentication yes
  195. #
  196. visudo
  197. # %sudo ALL=(ALL) NOPASSWD: /usr/sbin/sshd -D
  198. #
  199. sc stop lxssmanager
  200. #
  201. # >>atalho<<
  202. destino   c:\windows\system32\bash.exe -c "sudo /usr/sbin/sshd -D"
  203. icone     %USERPROFILE%\appdata\local\lxss\bash.ico
  204. #
  205. # >>vbs<<
  206. # c:\program files\openssh-win64\sshd.vbs
  207. set ws=wscript.createobject("wscript.shell")
  208. ws.run "c:\windows\system32\bash.exe -c 'sudo /usr/sbin/sshd -D'",0
  209. #
  210. # >>tarefa<< (não executa nem se configurado para iniciar no boot nem no logon, apenas sob demanda)
  211. #
  212. # geral
  213. #   nome: WSL SSHd
  214. #   executar:   somente quando o usuário estiver conectado (permite execução sob demanda)
  215. #             # estando o usuário conectado ou não (não permite sob demanda nem executa antes ou mesmo depois do logon)
  216. #   executar com privilégios mais altos: true
  217. #   oculto: true
  218. #   configurar para: windows 10
  219. # disparadores
  220. #   iniciar a tarefa: ao inicializar
  221. # # atrasar a tarefa em: 1 min
  222. #   habilitado: true
  223. # ações
  224. #   ação: iniciar um programa
  225. #   programa: c:\windows\system32\wscript.exe
  226. #   argumentos: "c:\program files\openssh-win64\sshd.vbs"
  227. # condições
  228. #   desmarcar tudo
  229. # configurações
  230. #   desmarcar tudo
  231. #   se a tarefa já estiver sendo executada: não iniciar nova instância
  232. #
  233. # >>serviço<< (erro ao inicializar)
  234. sc create wsl_sshd DisplayName= "WSL SSHd" start= auto binpath= "c:\windows\system32\bash.exe -c \"sudo /usr/sbin/sshd -D\""
  235. sc create wsl_sshd DisplayName= "WSL SSHd" start= auto binpath= "c:\windows\system32\wscript.exe \"c:\program files\openssh-win64\sshd.vbs\""
  236. sc delete wsl_sshd
  237. #
  238. # >>wabash<<
  239. # <http://github.com/cerebrate/wabash>
  240. choco install --reinstall -f wabash
  241. refreshenv
  242. where wabash
  243. bash -l
  244.   sudo -i
  245.     echo 'deb https://cerebrate.github.io/wsl-translinux/ xenial main' >| /etc/apt/sources.list.d/wsl-translinux.list
  246.     apt --allow-unauthenticated update
  247.     apt --allow-unauthenticated -y install wabashd
  248.     visudo
  249.     # ALL ALL=(root) NOPASSWD: /usr/sbin/service
  250.     vi /mnt/c/ProgramData/chocolatey/lib/wabash/tools/Wabash.exe.config
  251.     # <string>ssh</string>
  252.     exit
  253.   exit
  254. wabash
  255.  
  256. bash -c 'vi /mnt/c/ProgramData/chocolatey/lib/wabash/tools/Wabash.exe.config'
  257.  
  258.  
  259.  
  260. # >> chocolatey <<
  261. # <http://chocolatey.org/install>
  262.  
  263. iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
  264.  
  265.  
  266.  
  267. # >> win32-openssh <<
  268. # running bash from ssh (using built-in SSH Server Broker/Proxy) causes error 0x8007048f <http://github.com/Microsoft/BashOnWindows/issues/777>
  269. # <http://github.com/PowerShell/Win32-OpenSSH/releases>
  270. # <http://github.com/PowerShell/Win32-OpenSSH/wiki/Install-Win32-OpenSSH>
  271. # <http://github.com/PowerShell/Win32-OpenSSH/wiki/Troubleshooting-Steps>
  272. # <http://github.com/PowerShell/Win32-OpenSSH/wiki/Security-protection-of-various-files-in-win32-openssh>
  273. # <http://chocolatey.org/packages/openssh>
  274. # <http://winscp.net/eng/docs/guide_windows_openssh_server>
  275.  
  276. vi C:/Program Files/OpenSSH/sshd_config
  277. # Port 22
  278. # ListenAddress 0.0.0.0
  279. # PermitRootLogin yes
  280. # PasswordAuthentication yes
  281. # ChallengeResponseAuthentication yes
  282. # X11Forwarding yes
  283. # UsePrivilegeSeparation no
  284. # PidFile "C:/Program Files/OpenSSH/logs/sshd.pid"
  285. # KbdInteractiveAuthentication yes
  286. # ForceCommand powershell.exe
  287. ssh-keygen -A
  288. # cmd
  289. sc query sshd
  290. sc start sshd
  291. sc stop  sshd
  292.  
  293.  
  294.  
  295. # >> chocolatey openssh <<
  296. # <http://chocolatey.org/packages/openssh>
  297. # <http://github.com/DarwinJS/ChocoPackages/blob/master/openssh/readme.md>
  298.  
  299.   choco upgrade openssh
  300.   # new prompt:
  301.   refreshenv
  302.  
  303. # Get-ExecutionPolicy -List
  304. # Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
  305. # iwr https://chocolatey.org/install.ps1 -UseBasicParsing | iex
  306. # choco install win32-openssh
  307. # cd 'C:\Program Files\OpenSSH-Win64\'
  308. # install-sshd.ps1
  309. # ssh-keygen -A
  310. # New-NetFirewallRule -Protocol TCP -LocalPort 22 -Direction Inbound -Action Allow -DisplayName SSH
  311. # install-sshlsa.ps1
  312. # Control Panel > System and Security > Administrative Tools > Services > SSHD > Action > Properties > Startup Type > Automatic > Confirm > Start
  313. # setar senha do usuário 'administrador'
  314. # ssh localhost
Add Comment
Please, Sign In to add comment