SSH远程登录
简介
密钥对生成
在win10系统,使用已有的ssh,进行命令行生成:
ssh-keygen -t rsa -b 4096
生成的目录,默认会放在用户的.ssh(.表示隐藏的意思,类似Linux)。
C:\Users\XXX(username).ssh
注意,如果之前用vscode做过ssh链接,该目录下会有 know_hosts文件,我理解相当于ssh的指纹缓存,先都删掉,否则后面会有冲突。
Enter passphrase (empty for no passphrase):
这里直接回车,如果填了密码,后面vs链接还要再输入对应密码。
私钥
自己保存在本地,文件名为:id_rsa
公钥
公钥文件名:id_rsa.pub, 拷贝你要链接的远程linux系统中。
保存位置: 如果.ssh没有就创建一个,因为默认配置文件路径就是这样的。
cp id_rsa.pub ~/.ssh/authorized_keys
并修改下目录权限,如只root,就600
chmod 600 ~/.ssh/authorized_keys
文件权限,如只root登录,就700
chmod 700 ~/.ssh/authorized_keys
同时配置下ssh配置文件:
sudo vim /etc/ssh/sshd_config
找到下面两项:
PermitRootLogin yes # 这个不写,没法用root登录,会提示 Permission denied, please try again.
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
PasswordAuthentication no 或者直接注释掉
重启ssh
sudo service sshd restart
顺便: 开启启动ssh: systemctl enable ssh
本地 VScode配置
在ssh插件中添加使用身份文件一行就可以了
IdentityFile "C:\Users\xxx\.ssh\id_rsa" (xxx根据当前路径来)
F1 输入 Remote-SSH:Open configure file
选择 :user
vscode 与 WSL配合
安装 插件
安装好插件后,直接在对应的WSL里面输入 code
就可以在vscode弹出新的窗口了。
微软为我们提供了一个默认的变量可以直接指向WSL的目录,wsl$ 你可以在运行(win+R)或资源管理器的路径里直接输入\\wsl$进入Ubuntu的目录
知道地址了,就可以映射到驱动器了,右键网络,选择映射驱动器,把地址放上去就可以了。
Windows terminal字体:
下载字体
安装到系统内。
在VSCODE配置项
editor.fontFamily
中添加
'Cascadia Code'
例如我的配置就是
"editor.fontFamily": "'Cascadia Code',Consolas, 'Courier New', monospace",
将配置项
editor.fontLigatures
改为
true
例如我的配置就是
"editor.fontLigatures": true
新增配置总结:
{
"launch": {
"configurations": [],
"compounds": []
},
"workbench.colorTheme": "Panda Syntax",
"editor.fontLigatures": null,
"editor.fontSize": 22,
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\cmd.exe",
"terminal.integrated.fontSize": 18,
"terminal.integrated.lineHeight": 1.6,
"terminal.integrated.letterSpacing": 0.1,
"terminal.integrated.cursorBlinking": true,
"terminal.integrated.fontFamily": "Lucida Console", //字体设置
"terminal.integrated.shell.linux": "/bin/zsh",
"terminal.integrated.drawBoldTextInBrightColors": true,
"emmet.triggerExpansionOnTab": true,
"emmet.showAbbreviationSuggestions": true,
"emmet.showExpandedAbbreviation": "always",
"window.zoomLevel": 1,
"editor.wordWrap": "on",
"editor.detectIndentation": false,
// 重新设定tabsize
"editor.tabSize": 2,
//失去焦点后自动保存
"files.autoSave": "onFocusChange",
// #值设置为true时,每次保存的时候自动格式化;
"editor.formatOnSave": false,
//每120行就显示一条线
"editor.rulers": [
],
// 在使用搜索功能时,将这些文件夹/文件排除在外
"search.exclude": {
"**/node_modules": true,
"**/bower_components": true,
"**/target": true,
"**/logs": true,
},
// 这些文件将不会显示在工作空间中
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true,
"**/*.js": {
"when": "$(basename).ts" //ts编译后生成的js文件将不会显示在工作空中
},
"**/node_modules": true
},
"remote.SSH.remotePlatform": {
"Parrot": "linux"
},
"workbench.iconTheme": "vscode-icons",
"editor.renderControlCharacters": true,
"terminal.integrated.cursorStyle": "line",
"terminal.integrated.copyOnSelection": true,
"terminal.integrated.cursorWidth": 2,
}
解决 VSCODE :Pwntools gdb窗口问题
[ERROR] Could not find terminal binary 'vscode'. Set context.terminal to your terminal.
原来的代码是直接attach调用:
p = process('./dice_game')
gdb.attach(p)
- 现在修改为:
p = process('./dice_game')
context.terminal = ['tmux','splitw','-h']
gdb.attach(proc.pidof(p)[0],gdbscript="b main")
- 运行脚本的时候,先配置tmux:
- tmux set mouse on (设定鼠标滚动支持)
- 再执行 tmux
再输入python exploit.py,[^记得务必在tmux下执行脚本] ,然后就可以发现使用gdb进行debug了,整个命令行界面分为一左一右两部分。
插件
vscode-icons
F1 激活配置
问题
问题1
解决方法:
- 检查Settings.json 配置,是否加了对端 remote平台信息:
{
"remote.SSH.remotePlatform":{ //remote system 1: Parrot OS
"Parrot": "linux",
}, // 注意用逗号隔开
"remote.SSH.remotePlatform":{ // remote system 2 : Ubuntu OS
"Ubuntu": "linux",
},
"terminal.integrated.shell.linux": "/bin/zsh",
"editor.fontSize": 18,
"editor.accessibilityPageSize": 18,
"window.zoomLevel": 1,
//"terminal.external.windowsExec": "D:\\1software\\2cmder\\Cmder.exe",
"terminal.external.windowsExec": "C:\\Windows\\System32\\cmd.exe",
"terminal.integrated.fontSize": 18,
"remote.SSH.defaultForwardedPorts": [
],
"extensions.ignoreRecommendations": false,
"files.associations": {
},
"code-runner.runInTerminal": true,
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\cmd.exe",
"[c]":{
"files.encoding": "gbk",
"editor.quickSuggestions":true,
},
"[cpp]": {
"editor.wordBasedSuggestions": true,
},
"code-runner.ignoreSelection": true,
}
注意,每有一个系统,都要加,保留最后的逗号 ,
“remote.SSH.remotePlatform”:{
“Ubuntu”: “linux”, (系统名【自定义】:系统类型)
},
-排查下 IP地址对不?
虚拟机情况,可能会存在切换链接模式后,重新分配IP地址情况,此时就要排查修改原配置,找到 SSH插件旁边的齿轮,修改新地址:
- 最后删除 know_hosts原缓存内容。
路径:
C:\Users\xxx\.ssh\known_hosts
问题2
如果登录,仍然需要密码,大概率可能找不到私钥
ssh -v root@远程服务器IP
验证ssh登录远程。
查看私钥路径是否正确。
问题3
不能创建 .vscode
Windows中不能创建以"."开头文件。
解决办法:
在项目根目录下面创建vscode目录;
在项目根目录下面按住Shift键并邮件然后选择“在此处打开命令窗口”
执行命令 ren vscode .vscode