Colderleo's blog Colderleo's blog
首页
Linux
C++
Python
前端
工具软件
mysql
索引
关于
GitHub (opens new window)

Colder Leo

热爱代码的打工人
首页
Linux
C++
Python
前端
工具软件
mysql
索引
关于
GitHub (opens new window)
  • 常见程序性能开销cost、latency延迟耗时的经验值
  • 面试常见问题
  • 静态链接-动态链接-elf详解-elfloader
  • 动态库和静态库的依赖问题
  • glibc和ld的编译调试-为某程序单独设置ld
  • dl_iterate_phdr遍历linkmap头、获取so加载地址
  • shell、bash语法和脚本模板
  • so文件查找路径
  • 逻辑地址-线性地址or虚拟地址-物理地址
  • 通过ELF读取当前进程的符号表并获取符号的版本信息
  • 虚拟内存,cache,TLB,页表
  • 用户内存空间分布和mmap
  • numa网卡绑定
  • 隔核绑核、服务器优化
  • popen底层原理和仿照实现-execl
  • tmux用法
  • ASLR机制
  • 程序后台运行、恢复前台nohup
  • 大页内存huge_page
  • 用perf查看page-fault
  • Bash设置显示全部路径
  • 查看socket fd状态,设置nonblock
  • cout输出到屏幕的过程
  • 多进程写同一文件-write原子性-log日志
  • vim用法
  • epoll用法
  • signal信号、软中断、硬中断、alarm
  • 内核模块
  • 读写锁之pthread_rwlock和内核rwlock自旋读写锁
  • systemtap
  • xargs、awk用法
  • openssl libssl.so.10.so缺失问题
  • netstat用法
  • fork函数
  • tcp延迟确认ack
  • 90.centos7上一次std-string编译错误定位
  • docker用法
  • find用法
  • dmesg
  • gcc编译用法
  • avx-sse切换惩罚
  • Centos7防火墙
  • chmod用法
  • kernel-devel安装版本
  • Linux-Centos7系统安装、网络设置、常见报错
  • linux下g++编译c++文件
  • MegaCli 安装及使用
  • mysql
  • mysql忘记密码修改方法
  • set用法
  • crontab
  • ssh传文件scp
  • ssh连接
  • tcpdump、tshark、tcpreplay用法
  • ubantu root登录以及创建新用户
  • ubuntu安装g++和gdb
  • uClibc编译失败解决方法
  • win10安装WSL open-ssh
    • wsl版本选择
    • win10安装wsl后设置root为默认登录账户
    • 设置软连接方便访问
    • 切换至root后,可安装以下常用软件:
    • win10安装wsl-ssh
    • win10安装官方的ssh
    • 再之前安装失败的过程
  • yum升级git
  • 比较so文件版本-md5sum
  • 查看磁盘信息
  • 合并两个硬盘,挂载到一个文件夹下
  • 软件安装目录usr-local-src
  • 下载centos历史版本
  • sh脚本转可执行文件、加密
  • Linux
gaoliu
2021-10-06
目录

win10安装WSL open-ssh

# wsl版本选择

  • 电脑性能不好选wsl1,性能好选wsl2或者虚拟机。
  • wsl1选Ubuntu-20.04, Ubuntu-22.04的gdb有点问题。
  • pwershell执行wsl -l -v查看安装的wsl版本

# win10安装wsl后设置root为默认登录账户

  • 应用商店安装Ubuntu-20.04,启动后设置普通用户的用户名和密码
  • sudo passwd root, 设置root密码
  • 先powershell停止wsl服务 net stop lxssmanager
  • 再设置默认登录为root /c/Users/用户名/AppData/Local/Microsoft/WindowsApps/ubuntu2004.exe config --default-user root
  • 重新进入wsl

# 设置软连接方便访问

可以将常用目录软连接至/root下面,方便切换 比如常用目录为/mnt/c/dorit

ln -s /mnt/c/dorit/ /root/dorit
1

# 切换至root后,可安装以下常用软件:

sudo apt-get update
sudo apt-get install gcc
sudo apt-get install gdb

1
2
3
4

如果安装源连不上,或者连接速度太慢,可尝试更换apt源 https://www.cnblogs.com/codingbigdog/p/16324800.html (opens new window) 20.04STL源

# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
1
2
3
4
5
6
7
8
9
10
11
12
13

# win10安装wsl-ssh

windows 自带的ssh服务器功能貌似有问题,可以先安装wsl,再在wsl上安装ssh

# 安装WSL:
  • https://www.jianshu.com/p/cd4d604e0b44
  • windows添加或删除功能,开启WSL
  • 从windows应用商店里安装ubantu STL
# ubantu安装ssh

https://blog.csdn.net/qq_38558270/article/details/88531795

  1. 先设置apt 安装源
# 备份原来的源配置
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

# 编辑
sudo vim /etc/apt/sources.list

# 替换为下面的内容
deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse


# 更新软件列表
sudo apt-get update
# 更新软件
sudo apt-get upgrade
# 更新软件(自动处理依赖):
sudo apt-get dist-upgrade
# 下载中文语言包:
sudo apt-get install language-pack-zh-han*

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
  1. 然后卸载自带的,重新安装,因为自带貌似有问题
sudo apt-get remove openssh-server
sudo apt-get remove openssh-client

# 这里很可能安装错误,如果出错看下面的方法
sudo apt-get install openssh-server
sudo apt-get install openssh-client
1
2
3
4
5
6

安装ssh如果提示错误:E: Could not read response to hello message from hook [ ! -f /usr/bin/snap ] , 则执行

sudo rm -rf /etc/apt/apt.conf.d/20snapd.conf
1
  1. 修改配置文件:
# 备份
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak

# 修改配置文件
sudo vim /etc/ssh/sshd_config

# 修改下面的内容。 Port设置成2022,是为了不占用windows的22端口。看自己喜好
Port 2022
PasswordAuthentication yes
PermitRootLogin yes
# 修改完成后重启服务

sudo service ssh restart

# ssh加入开机自启动。 注意wsl这样设置似乎没用。想开机启动参考下面的方法。
sudo systemctl enable ssh
# 或者下面的
vi /etc/rc.local
加入:service ssh start

# 注意上面的服务名在ubuntu上是ssh,在centos上是sshd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

# 其他设置

  1. 设置root密码
sudo passwd root
1
  1. 设置wsl开机启动 参考 https://zhuanlan.zhihu.com/p/47733615 里面的评论,新建wsl_start.bat脚本放在startup文件夹。该脚本即启动了wsl又启动了wsl内的ssh

wsl_start.bat

wsl -u root /etc/init.d/ssh start
1

# win10安装官方的ssh

之前安装了ssh后vscode的remote-ssh不能用,现在更新后可以了,remote ssh连上的时候回提示选windows/linux。

# windows安装open-ssh官方文档

https://docs.microsoft.com/zh-cn/windows-server/administration/openssh/openssh_install_firstuse

在windows应用-可选功能里安装ssh server

  • 默认安装在C:/Program Files/OpenSSH/
  • 配置文件: C:\ProgramData\ssh

安装完成后管理员打开powershell,启动ssh服务,配置防火墙等

Start-Service sshd
# OPTIONAL but recommended:
Set-Service -Name sshd -StartupType 'Automatic'
# Confirm the Firewall rule is configured. It should be created automatically by setup. 
Get-NetFirewallRule -Name *ssh*
# There should be a firewall rule named "OpenSSH-Server-In-TCP", which should be enabled
# If the firewall does not exist, create one
New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
1
2
3
4
5
6
7
8

# 登陆失败时新建用户

默认登陆时用户名和密码可以用windows的账户,如果登陆失败,可尝试在 计算机管理-本地用户和组 中新建用户,赋予管理员权限,然后登陆。

# bad owener or permission on .ssh/config

参考 https://www.cnblogs.com/microestc/p/10840315.html

将~/.ssh/config剪切至c:/programdata/ssh/ssh_config (config重命名为ssh_config)

# id_rsa免密登陆

参考 https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_keymanagement

假设需要从某个客户单电脑用户zhangsan连接到服务器电脑用户school上

  1. 在客户端zhangsan个人文件夹下创建公钥秘钥对

    # cd到当前用户目录下的.ssh文件夹, 比如C:\Users\zhangsan\.ssh
    cd ~\.ssh\
    
    # 创建密钥对, 会生成id_rsa, id_rsa.pub
    ssh-keygen
    
    1
    2
    3
    4
    5
  2. 复制id_rsa.pub到服务器school用户文件夹下~.ssh\authorized_keys上。如果authorized_keys不存在则创建,如果已存在就追加

  3. 服务端启动ssh-agent服务,然后管理员运行powershell,执行ssh-add

    cd ~\.ssh\
    ssh-add id_rsa
    
    1
    2

    如果提示id_rsa权限too open,可在其'文件属性-安全'中修复id_rsa权限:

    属性---安全---高级---禁用继承---保留转换,然后删除其他用户权限,只保留当前用户、administrators、SYSTEM。(当前用户可能不需要勾选完全控制)

    同时对authorized_keys也修复权限:

    客户端如果配置了.ssh\config,并且在读取的时候有问题,也用同样的方法对其修复权限。

  4. 在客户端尝试使用ssh -i登陆,如果仍要求输入密码,可尝试修改sshd_config。

    ssh -i ~/id_rsa school@localhost
    
    1

    参考 https://www.cnblogs.com/surplus/p/12466466.html

    以管理员权限打开 PowerShell,执行命令

    notepad C:\ProgramData\ssh\sshd_config
    
    1

    注释掉配置文件中的最后两行然后保存:

    #Match Group administrators
    #       AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys
    
    1
    2

    最后在服务管理器器中重启 OpenSSH SSH Server 服务,然后客户端就可以通过公钥认证的方式登录到远程服务器了。

    注意: 一定不要用 Repair-AuthorizedKeyPermission 命令修复 .ssh\authorized_keys 文件的权限。 也不要用echo "publickey" > .ssh\authorized_keys的方式创建 .ssh\authorized_keys 文件: 因为不需要用命令修复,所以不用安装Install-Module -Force OpenSSHUtils -Scope AllUsers,也不用管这个安装的时候签名错误的问题。

# 再之前安装失败的过程

可能是因为win10之前自己的bug,所以不成功。

# 修复.ssh/config权限

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process
import-Module E:\OpenSSH-Win64\OpenSSHUtils.psm1

Repair-UserSshConfigPermission ~/.ssh/config
Get-ChildItem ~\.ssh\* -Include "id_rsa","id_dsa" -ErrorAction SilentlyContinue | % {
    Repair-UserKeyPermission -FilePath $_.FullName @psBoundParameters
}
1
2
3
4
5
6
7

# vscode remote-ssh主页:

https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-ssh

# win10 open-ssh 秘钥登录

$REMOTEHOST="qiang.chen@localhost"

scp "$env:USERPROFILE\.ssh\siye_rsa.pub" "${REMOTEHOST}:~/tmp.pub"
ssh "$REMOTEHOST" "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat ~/tmp.pub >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys && rm -f ~/tmp.pub"
1
2
3
4

# ssh命令,指定秘钥文件登录:

https://www.ktanx.com/blog/p/4016

ssh -i ~/.ssh/liyddsshkey developer@192.168.1.237 -p 23

1
2

# powershell 签名验证码错误

https://jingyan.baidu.com/article/36d6ed1f6e18b61bcf4883de.html

set-ExecutionPolicy RemoteSigned
Set-ExecutionPolicy Unrestricted
1
2

这个试了不行。

另一种解放方法: https://www.cnblogs.com/gs0724/p/11763640.html 里面提到了win64-openssh的下载GitHub地址

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process

import-Module E:\OpenSSH-Win64\OpenSSHUtils.psm1

Repair-UserKeyPermission ~/.ssh/id_rsa-siye
Repair-UserSshConfigPermission ~/.ssh/config
Repair-AuthorizedKeyPermission ~\.ssh\authorized_keys
1
2
3
4
5
6
7
编辑 (opens new window)
上次更新: 2023/05/07, 17:27:54
uClibc编译失败解决方法
yum升级git

← uClibc编译失败解决方法 yum升级git→

最近更新
01
通过模板实现结构体成员拷贝-按成员名匹配
05-07
02
c++17通过模板获取类成员的个数
05-01
03
avx-sse切换惩罚
04-30
更多文章>
Theme by Vdoing | Copyright © 2019-2023 Colder Leo | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式
×