适用于Linux的windows子系统方法案例

开启wsl

首先:为了win10能运行适用于Linux的windows子系统,我们需要开启wsl
第一种方法:

开启wsl,开启步骤:按win + x进入Windows Power Shell,输入下面的命令开启,

1
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

开启后重启系统。

第二种

方法步骤

安装kali

进入应用商店,搜索kali,直接安装

安装VIM

1
sudo apt-get install vim

更新源

1
vi /etc/apt/sources.list
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#阿里云
deb http://mirrors.aliyun.com/kali kali-rolling main non-free contrib
deb-src http://mirrors.aliyun.com/kali kali-rolling main non-free contrib

#清华大学
deb http://mirrors.tuna.tsinghua.edu.cn/kali kali-rolling main contrib non-free
deb-src https://mirrors.tuna.tsinghua.edu.cn/kali kali-rolling main contrib non-free

#浙大
deb http://mirrors.zju.edu.cn/kali kali-rolling main contrib non-free
deb-src http://mirrors.zju.edu.cn/kali kali-rolling main contrib non-free

#中科大
deb http://mirrors.ustc.edu.cn/kali kali-rolling main non-free contrib
deb-src http://mirrors.ustc.edu.cn/kali kali-rolling main non-free contrib

#官方源
deb http://http.kali.org/kali kali-rolling main non-free contrib
deb-src http://http.kali.org/kali kali-rolling main non-free contrib
1
sudo apt-get update && sudo apt-get dist-upgrade
1
apt-get install apt-transport-https

配置SSH

在Linux子系统默认命令端输入,查看ip地址

1
ifconfig

配置SSH服务

1
2
sudo apt-get remove --purge openssh-server   ## 先删ssh
sudo apt-get install openssh-server ## 在安装ssh
1
2
sudo rm /etc/ssh/ssh_config                  ## 删配置文件
sudo service ssh --full-restart

修改sshd_config文件

1
vi /etc/ssh/sshd_config

将#PasswordAuthentication no的注释去掉,并且将NO修改为YES,kali中默认是yes

1
PasswordAuthentication yes

将PermitRootLogin without-password修改为

1
PermitRootLogin yes

使用xshell登录

上面命令执行完之后,在xshell中输入用户名和ip就可以通过xshell登录自己电脑的Linux。

配置永久解决方案

通过上面的方法,我们可以通过xshell登录自己电脑的Linux。但是断开之后重新开机,我们又需要重新配置SSH。因此,我们需要配置以下命令下,一劳永逸。

1
sudo service ssh --full-restart   ## 将该命令保存为service.sh,存在home目录下

配置好之后,下次开机,只需要在Linux子系统的默认终端运行sh service.sh命令后,关掉终端改用xshell登录即可。

图形界面

1
2
3
4
5
6
7
8
9
sudo apt-get install vnc4server tightvncserver
sudo apt-get install xrdp
sudo sed -i 's/port=3389/port=3390/g' /etc/xrdp/xrdp.ini
//apt-get install kali-defaults kali-root-login desktop-base kde-full
sudo apt-get install xorg
sudo apt-get install xfce4
//apt-get install kali-defaults kali-root-login desktop-base xfce4 xfce4-places-plugin xfce4-goodies
sudo echo xfce4-session >~/.xsession
sudo service xrdp restart

安装工具包

1
apt install kali-linux-full

win下关闭kali

1
net stop LxssManager

ubuntu下神奇的多线程apt-get

安装axel

1
sudo apt-get install axel

下载脚本apt-fast.sh

下载地址 http://www.mattparnell.com/linux/apt-fast/apt-fast.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# !/bin/sh
# apt-fast v0.03 by Matt Parnell http://www.mattparnell.com, this thing is fully open-source
# if you do anything cool with it, let me know so I can publish or host it for you
# contact me at admin@mattparnell.com

# Special thanks
# Travis/travisn000 - support for complex apt-get commands
# Allan Hoffmeister - aria2c support
# Abhishek Sharma - aria2c with proxy support
# Richard Klien - Autocompletion, Download Size Checking (made for on ubuntu, untested on other distros)
# Patrick Kramer Ruiz - suggestions - see Suggestions.txt
# Sergio Silva - test to see if axel is installed, root detection/sudo autorun

# Use this just like apt-get for faster package downloading.

# Check for proper priveliges
[ "`whoami`" = root ] || exec sudo "$0" "$@"

# Test if the axel is installed
if [ ! -x /usr/bin/axel ]
then echo "axel is not installed, perform this?(y/n)"
read ops
case $ops in
y) if apt-get install axel -y --force-yes
then echo "axel installed"
else echo "unable to install the axel. you are using sudo?" ; exit
fi ;;
n) echo "not possible usage apt-fast" ; exit ;;
esac
fi

# If the user entered arguments contain upgrade, install, or dist-upgrade
if echo "$@" | grep -q "upgrade\|install\|dist-upgrade"; then
echo "Working...";

# Go into the directory apt-get normally puts downloaded packages
cd /var/cache/apt/archives/;

# Have apt-get print the information, including the URI's to the packages
# Strip out the URI's, and download the packages with Axel for speediness
# I found this regex elsewhere, showing how to manually strip package URI's you may need...thanks to whoever wrote it
apt-get -y --print-uris $@ | egrep -o -e "(ht|f)tp://[^\']+" > apt-fast.list && cat apt-fast.list | xargs -l1 axel -a

# Perform the user's requested action via apt-get
apt-get $@;

echo -e "\nDone! Verify that all packages were installed successfully. If errors are found, run apt-get clean as root and try again using apt-get directly.\n";

else
apt-get $@;
fi

安装apt-fast

1
2
sudo mv /root/apt-fast.sh /usr/bin/apt-fast
sudo chmod +x /usr/bin/apt-fast

现在你已经可以使用apt-fast替代apt-get了
试一下

1
2
3
apt-fast update
apt-fast upgrade
apt-fast install XXXXX

魔改axel设置脚本

1
sudo vim /etc/axelrc

找到

1
num_connections = 4

默认的4线程
直接修改这个值
例如:十线程

1
num_connections = 10

Linux下的vim配置文件

1
vi ~/.vimrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
" Vim config file.


" Global Settings: {{{
syntax on " highlight syntax
filetype plugin indent on " auto detect file type

set nocompatible " out of Vi compatible mode
"set number " show line number
set numberwidth=3 " minimal culumns for line numbers
set textwidth=0 " do not wrap words (insert)
set nowrap " do not wrap words (view)
set showcmd " show (partial) command in status line
set ruler " line and column number of the cursor position
set wildmenu " enhanced command completion
set wildmode=list:longest,full " command completion mode
set laststatus=2 " always show the status line
set mouse= " use mouse in all mode
set foldenable " fold lines
set foldmethod=marker " fold as marker
set noerrorbells " do not use error bell
set novisualbell " do not use visual bell
set t_vb= " do not use terminal bell

set wildignore=.svn,.git,*.swp,*.bak,*~,*.o,*.a
set autowrite " auto save before commands like :next and :make
set cursorline
set hidden " enable multiple modified buffers
set history=1000 " record recent used command history
set autoread " auto read file that has been changed on disk
set backspace=indent,eol,start " backspace can delete everything
set completeopt=menuone,longest " complete options (insert)
set pumheight=10 " complete popup height
set scrolloff=5 " minimal number of screen lines to keep beyond the cursor
set autoindent " automatically indent new line
set cinoptions=:0,l1,g0,t0,(0,(s " C kind language indent options
set clipboard+=unnamed " shared clipboard
set noexpandtab " do not use spaces instead of tabs

set tabstop=4 " number of spaces in a tab
set softtabstop=4 " insert and delete space of <tab>
set shiftwidth=4 " number of spaces for indent
set expandtab " expand tabs into spaces
set incsearch " incremental search
set hlsearch " highlight search match
set ignorecase " do case insensitive matching
set smartcase " do not ignore if search pattern has CAPS
set nobackup " do not create backup file
"set noswapfile " do not create swap file
set backupcopy=yes " overwrite the original file

set encoding=utf-8
set termencoding=utf-8
set fileencoding=utf-8
set fileencodings=gb2312,utf-8,gbk,gb18030
set fileformat=unix

set background=dark
"colorscheme SolarizedDark_modified
"colorscheme wombat_modified
" gui settings
if has("gui_running")
set guioptions-=T " no toolbar
set guioptions-=r " no right-hand scrollbar
set guioptions-=R " no right-hand vertically scrollbar
set guioptions-=l " no left-hand scrollbar
set guioptions-=L " no left-hand vertically scrollbar
autocmd GUIEnter * simalt ~x " window width and height
language messages zh_CN.utf-8 " use chinese messages if has
endif

" Restore the last quit position when open file.
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g'\"" |
\ endif
"}}}

" Key Bindings: {{{
let mapleader = ","
let maplocalleader = "\\"

" map : -> <space>
map <Space> :

" move between windows
nmap <C-h> <C-w>h
nmap <C-j> <C-w>j
nmap <C-k> <C-w>k
nmap <C-l> <C-w>l

" Don't use Ex mode, use Q for formatting
map Q gq

"make Y consistent with C and D
nnoremap Y y$

" toggle highlight trailing whitespace
nmap <silent> <leader>l :set nolist!<CR>

" Ctrl-E to switch between 2 last buffers
nmap <C-E> :b#<CR>

" ,e to fast finding files. just type beginning of a name and hit TAB
nmap <leader>e :e **/

" Make shift-insert work like in Xterm
map <S-Insert> <MiddleMouse>
map! <S-Insert> <MiddleMouse>

" ,n to get the next location (compilation errors, grep etc)
nmap <leader>n :cn<CR>
nmap <leader>p :cp<CR>

" Ctrl-N to disable search match highlight
nmap <silent> <C-N> :silent noh<CR>

" center display after searching
nnoremap n nzz
nnoremap N Nzz
nnoremap * *zz
nnoremap # #zz
nnoremap g* g*zz
nnoremap g# g#z
"}}}

" mru
let MRU_Window_Height = 10
nmap <Leader>r :MRU<cr>

" taglist
let g:Tlist_WinWidth = 25
let g:Tlist_Use_Right_Window = 0
let g:Tlist_Auto_Update = 1
let g:Tlist_Process_File_Always = 1
let g:Tlist_Exit_OnlyWindow = 1
let g:Tlist_Show_One_File = 1
let g:Tlist_Enable_Fold_Column = 0
let g:Tlist_Auto_Highlight_Tag = 1
let g:Tlist_GainFocus_On_ToggleOpen = 1
nmap <Leader>t :TlistToggle<cr>

" nerdtree
let g:NERDTreeWinPos = "right"
let g:NERDTreeWinSize = 30
let g:NERDTreeShowLineNumbers = 1
let g:NERDTreeQuitOnOpen = 1
nmap <Leader>f :NERDTreeToggle<CR>
nmap <Leader>F :NERDTreeFind<CR>

"paste
vmap <C-c> "+y
nmap <C-v> "+p
set pastetoggle=<F12>

"C,C++ Java Compile and run by F5
map <F5> :call CompileRunGcc()<CR>
func! CompileRunGcc()
exec "w"
if &filetype == 'c'
exec "!g++ % -o %<"
exec "! ./%<"
elseif &filetype == 'cpp'
exec "!g++ % -o %<"
exec "! ./%<"
elseif &filetype == 'java'
exec "!javac %"
exec "!java %<"
elseif &filetype == 'sh'
:!./%
endif
endfunc

"C,C++ debug
map <F8> :call Rungdb()<CR>
func! Rungdb()
exec "w"
exec "!g++ % -g -o %<"
exec "!gdb ./%<"
endfunc

PS1

1
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;31m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '

bashrc

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac

# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth

# append to the history file, don't overwrite it
shopt -s histappend

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
#shopt -s globstar

# make less more friendly for non-text input files, see lesspipe(1)
#[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi

# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-color) color_prompt=yes;;
esac

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi

if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;31m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
;;
*)
;;
esac

# colored GCC warnings and errors
export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'

# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
alias dir='dir --color=auto'
alias vdir='vdir --color=auto'

alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi

# some more ls aliases
alias ll='ls -l'
alias la='ls -A'
alias l='ls -la'

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
fi

评论