vscode 配合wsl做linux下的開發

klaus_x發表於2020-11-11

vscode 配合wsl做linux下的開發

安裝wsl

直接在商店裡面搜尋wsl
在這裡插入圖片描述
記住在windows功能項裡面勾選 適用於Linux的Windows子系統
在這裡插入圖片描述

配置wsl

安裝完成之後輸入wsl
在這裡插入圖片描述
進入剛剛安裝的wsl
1.更換阿里雲映象

sudo sed -i s@/archive.ubuntu.com/@/mirrors.aliyun.com/@g /etc/apt/sources.list
sudo apt update -y
sudo apt upgrade -y

2.安裝ssh服務
這裡剛剛進去我也是被坑了一下 ps -aux | grep ssh什麼都沒有,重啟一下直接報錯

-> # service ssh restart
Could not load host key: /etc/ssh/ssh_host_rsa_key
Could not load host key: /etc/ssh/ssh_host_ecdsa_key
Could not load host key: /etc/ssh/ssh_host_ed25519_key
* Restarting OpenBSD Secure Shell server sshd
Could not load host key: /etc/ssh/ssh_host_rsa_key
Could not load host key: /etc/ssh/ssh_host_ecdsa_key
Could not load host key: /etc/ssh/ssh_host_ed25519_key

然後重新安裝一下

apt remove openssh-server 
apt install openssh-server

這裡需要改一下配置 sudo vim /etc/ssh/sshd_config改下面2個點

13 Port 22
......
55 # To disable tunneled clear text passwords, change to no here!
56 PasswordAuthentication yes
57 #PermitEmptyPasswords no

port改成22, 56行的密碼認證開啟,之前no好像還需要一個認證檔案

vscode連線wsl

然後根據自己的ip就可以連上去了
vscode就直接連上去了,我另外一個用SecureCRT也很方便
在這裡插入圖片描述
安裝c/c++環境,連線到github上面的專案

sudo apt-get install gdb 
sudo apt-get install g++

vscode的很神奇,好像直接都配置好了,我進去也是直接的好的配置資訊
在這裡插入圖片描述
然後launch.json好像直接生成

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "g++ - 生成和除錯活動檔案",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "為 gdb 啟用整齊列印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: g++ build active file",
            "miDebuggerPath": "/usr/bin/gdb"
        }
    ]
}

另外一個tasks.json

{
    "tasks": [
        {
            "type": "shell",
            "label": "C/C++: g++ build active file",
            "command": "/usr/bin/g++",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "/usr/bin"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": "build",
            "detail": "Generated task by Debugger"
        }
    ],
    "version": "2.0.0"
}

新建一個hello.cpp按下F5按要求好像沒有什麼卡殼的,很順利,我遇到一個生成的可執行hello與hello.cpp不在一個路徑,生成的hello和.vscode一個目錄,老是報錯後來我重啟又好了,奇怪

上傳GitHub

然後就是自己的github倉庫
自己的clone到本地,配置一下自己的資料倉儲資訊

*** Please tell me who you are.
Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: empty ident name (for <klaus@DESKTOP-1J0SU5A.localdomain>) not allowed

然後配置完成之後,輸入自己的賬號密碼完成更新,一句話完成更新

git add -A && git commit -m “refresh” && git push

詳細內容如下:

klaus@DESKTOP-1J0SU5A:~/wintype/Daily-algorithm$ git config --global user.email *****@outlook.com
klaus@DESKTOP-1J0SU5A:~/wintype/Daily-algorithm$ git config --global user.name *******
klaus@DESKTOP-1J0SU5A:~/wintype/Daily-algorithm$ git add -A && git commit -m "refresh" && git push
[master d695eb9] refresh
1 file changed, 9 insertions(+)
create mode 100644 hello/hello1.cpp
Username for 'https://github.com': **********
Password for 'https://***********@github.com': **********
Counting objects: 8, done.
Delta compression using up to 8 threads

github上就完成更新了。

同步的時候出現了一個每次都要輸入賬號和密碼的問題

klaus@DESKTOP-1J0SU5A:~/wintype/Daily-algorithm$ git push origin master
The authenticity of host 'github.com (192.30.255.113)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E********mTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,192.30.255.113' (RSA) to the list of known hosts.
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

這裡需要生成一個ssh-key

klaus@DESKTOP-1J0SU5A:~/wintype/Daily-algorithm$ ssh-keygen -t rsa -C "******@outlook.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/home/****/.ssh/id_rsa): /home/*****/.ssh/id_rsa
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/*****/.ssh/id_rsa.
Your public key has been saved in /home/*****/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:4AXCEcp2UyMCSRNj1UXgysG+*****/NnIJ9oz/RtI ******@outlook.com
The key's randomart image is:
+---[RSA 2048]----+
|oO++B+Bo         |
|o.=+oB o         |
.....
| . .    +        |
|         o       |
|        .        |
+----[SHA256]-----+
klaus@DESKTOP-1J0SU5A:~/wintype/Daily-algorithm$
klaus@DESKTOP-1J0SU5A:~/wintype/Daily-algorithm$ cat ~/.ssh/id_rsa.pub

然後把生成的金鑰拷貝到github裡面

相關文章