Use openSSH to connect to linux and the problems encountered

Tip: After the article is written, the table of contents can be automatically generated. How to generate it can refer to the help document on the right


foreword

在windows宿主机上使用系统自带的openSSH连接linux。
(本例连接的vmware中centos7)


1. openSSH

1. Check whether the machine is installed

win+R and enter openssh
insert image description here
to jump to the directory where openSSH is located (mine is C:\Windows\System32\OpenSSH).
insert image description here
If not, please install it yourself. Generally, the system comes with it.

2. Configure environment variables

Add the directory where openSSH is located in the system variable path
insert image description here

insert image description here

3. Basic commands

win+R, enter cmd to run, and then enter ssh
insert image description here
to see the optional parameter list displayed in the help option. Generally, you only need to use user@host for connection.

Learning openssh can refer to: https://blog.csdn.net/weixin_44570083/article/details/109435794
https://blog.csdn.net/asmartkiller/article/details/112209755

2. Connection

1. Application

cmd input ssh user@localhost (enter your own user and ip address to connect to linux)
insert image description here

If the connection is successful, the following content is displayed:
insert image description here
enter yes, and then enter the password to complete the connection.

2.bug

There are probably two reasons for the bug:
1. The C:\Users\xxxx/.ssh/config file has no permissions, refer to:
https://blog.csdn.net/weixin_44749184/article/details/124188026
https://blog.csdn .net/qq_37596943/article/details/122349066

2. If this problem occurs when using vscode to connect to linux, the solution: https://zixizixi.cn/windows_vscode_ssh_error_bad-owner-or-permissions

3. Conflict between git ssh and openssh, solution:
https://haolaoshi.blog.csdn.net/article/details/108882983

4. If it doesn’t work, consider deleting the config file directly (there may be problems with the config file being modified)

I report the Bad owner or permissions on C:\Users\xxxx/.ssh/config problem, which
is actually a conflict between git ssh and openssh. Check the environment variables as follows:
insert image description here

You can also search for git bash with win + s to view the file location. There are three files
insert image description here
ssh_config and sshd_config in etc/ssh in this directory, which are related to the files in the C:\Users\xxxx/.ssh directory. At this point, I found the problem of Bad owner or permissions on C:\Users\xxxx/.ssh/config.
insert image description here

3. Solve bugs

The solution to the configuration conflict between openssh and git ssh:
1. Remove openssh from the environment variable and use git ssh.
2. Use ssh root@loalhost [-F config_file] to manually specify the location of the config file, so you don’t need to remove openssh

Here is the second solution:

Create an openssh_config empty file under C:\Users\xxxx\ (call it anything)
insert image description here

cmd input ssh root@loalhost -F openssh_config, then enter the password

insert image description here

Three, shell tools

Recommend an easy-to-use shell tool windows terminal for easy connection to linux

insert image description here

1. Install

Download directly from the Microsoft store
insert image description here

2. Configuration

Start the windows terminal, press and hold (ctrl + , ) to open the settings, and choose to add a new configuration file
insert image description here

There are many configuration items here, the main configurations are as follows:

1. Name: take whatever you want
2. Command line:
C:\Windows\System32\OpenSSH\ssh.exe -FC:\Users\xxx\openssh_config -p 22 root@host
3. Startup directory: use the parent process directory
4. Icon :
Can be generated from https://www.logosc.cn/, enter the website and select [Online LOGO Design]
5. Tab title: do not fill in
6. [Run as administrator] and [Hide from drop-down menu] do not open
7. [Appearance] and [Advanced] customization in other settings

insert image description here

After completing the changes, click the drop-down box to select the newly created configuration file option, and enter the password

insert image description here

4. Key

There are too many online tutorials, recommended address:
https://blog.csdn.net/qq_34142812/article/details/102155760

Guess you like

Origin blog.csdn.net/m0_61849361/article/details/127307081