Configure your own ssh gadget

2020/05/15 08:00
Reading number 203

preface

In the process of testing, we often need to deal with the server. At this time, we need a better ssh tool to facilitate our work. However, these tools will have more or less bugs or coding problems, especially on the mac side. Because the mac terminal has its own ssh function, which is also convenient, you can use the mac terminal to try to configure a more convenient remote connection window.


Specific process

1. Connection

     Since the Mac has its own ssh terminal, you can directly connect to the corresponding server through the ssh command. The specific method is as follows:

 ssh  username @ip   

In this way, you can connect to a specific server to perform the required operations.


2. Environment configuration

Because each time you connect, you need to enter the command required in the previous step to connect. Although the command is relatively short, it is still not very inconvenient on the whole. So you can configure the command to the environment variable and customize the name of your own opening method. We can use alias to customize the name for implementation.

 alias The command is used to set the alias of the command. We can use this command to simplify some longer commands. use alias The user must use single quotation marks when '' Use the original command to prevent special characters from causing errors.
Main configuration mode: 1. Edit the user's configuration file~/. bash_profile or system configuration/etc/profile two alias New command= 'Original command - options/parameters' For example alias 10010 = 'ssh root@1.2.3.4 ' 3. Save and exit four source configuration file

3. Input of user name and password

After configuring the environment, we will find that when connecting, we still need to repeat the authentication, as shown in the figure below, and the user name and password also need to be authenticated:

Therefore, a scheme is needed to skip the verification process of user name and password. Here, expect matching is adopted. The main process is as follows:

 one Install expect tool brew install expect 2.  Write your own startup script (example)    #!/ usr/bin/expect   set password $1 set answer $2
  spawn ssh  root@ip_address
expect " *yes* " send "$answer\n"
expect "*password:" send "$password\n"
Interact//The operation is completed

4. File upload and download

After login, compared with other ssh tools, there is still a lack of upload and download functions. Compared with sz and rz, scp can still be used to upload and download files on the mac side, and the flexibility will be higher. The main upload and download methods are as follows:

 1.  Download:    scp  root@ip_address :/root/test.txt/Users/mac/Desktop is to download/root/test.txt from the server to the local/Users/mac/Desktop directory. Notice the space between the two addresses! two upload    scp -r test  root@ip_address :/root/Upload the test directory under the current directory to the server's/root/directory Note: The target server needs to enable write permissions.


Actual use

According to the previous steps, Xiaobian has configured its own ssh tool on its own computer. Of course, the previous steps are only the basis. You can also expand the functions to facilitate use according to your own needs. Here are some of the use of Xiaobian:

  1. To view your current server:

    2. Select one to log in:


epilogue

Through the above steps, you can easily configure your own ssh gadget, and then you won't have to worry about using the hidden bugs of other tools, downloading and cracking. You can also use your own brain holes to make something more suitable for your habits and daily life.



This article is shared from the WeChat official account Sogou QA.
In case of infringement, please contact support@oschina.cn Delete.
Participation in this article“ OSC Source Innovation Plan ”, welcome you to join us and share with us.

Expand to read the full text
Loading
Click to lead the topic 📣 Post and join the discussion 🔥
Reward
zero comment
zero Collection
zero fabulous
 Back to top
Top