Category Archives: Linux

Git Bash Run “ssh-add pathName” Error: “Could not open a connection to your authentication agent.”

Recently, when I contacted laravel, I started using GIT and installed windows for GIT. When I pushed GitHub, I failed the verification. I didn’t add SSH to GitHub account

Follow the tutorial step by step to “SSH add pathname” and the following information will appear:

Most of Baidu said to execute Eval ‘SSH agent – s’ first. However, as shown in the figure above, it has already been executed, and it is still so. So continue with Baidu. Fortunately, we have finally found a solution

Solution: SSH agent is required to start bash, or to hang bash under SSH agent

[specific operation]:

way@DESKTOP-8CTQ9EA MINGW64 /d/XAMpp/htdocs/gitwork (master)
$ ssh-agent bash --login -i

way@DESKTOP-8CTQ9EA MINGW64 /d/XAMpp/htdocs/gitwork (master)
$ ssh-add
Identity added: /c/Users/way/.ssh/id_rsa (/c/Users/way/.ssh/id_rsa)

 

Node uses SSH2 SFTP Client to upload and download FTP files

Operating environment.

win7; node 10.15.1

The implementation steps are as follows

Step 1: Installation ssh2-sftp-client

npm install ssh2-sftp-client
// or
yarn add ssh2-sftp-client

Step 2: code implementation

 1 let Client = require('ssh2-sftp-client');
 2 
 3 function put(localPath, romotePath) {
 4     let sftp = new Client();
 5     sftp.connect({
 6         host: 'xx.xx.xx.xx', // Servers IP
 7         port: '22',
 8         username: 'xxxx',
 9         password: 'xxxxxx'
10     }).then(() => {
11         // upload
12         // return sftp.fastPut(localPath, romotePath);
13         // Download
14         return sftp.get(localPath, romotePath);
15     }).then((data) => {
16         // console.log(localPath + "Uploaded");
17         console.log(localPath + "Downloaded");
18         sftp.end();
19     }).catch((err) => {
20         console.log(err, 'catch error');
21     });
22 }
23 
24 let srcPath = 'D:\\MyDisk\\my-project\\node\\file\\test-copy.txt',
25     localPath = path.join(__dirname, 'test.txt'),
26     romotePath = '/home/xx/xx/webapps/xx/test.txt';
27 
28 // Upload file
29 // The first parameter is the local path of the file to be uploaded; the second parameter is the address where the server is stored
30 // put(localPath, romotePath);
31 // Download the file
32 // The first parameter is the address of the server where the file to be downloaded is stored; the second parameter is the local path
33 put(romotePath, srcPath);

note:

1. When uploading files, the fastput method is used, and the put method is used to upload files and report errors

2. SSH2 sfttp client official website document address

How to Solve Error: ssh_exchange_identification:read connection reset by peer

The server changed the password. After trying the password for many times, it appears:

ssh_exchange_identification: read: Connection reset by peer

You can view the connection details through SSH – V

OpenSSH_6.6.1, OpenSSL 1.0.1k-fips 8 Jan 2015 debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 56: Applying options for * debug1: Connecting to xxx [xx] port 22. debug1: Connection established. debug1: identity file /home/yanue/.ssh/id_rsa type -1 debug1: identity file /home/yanue/.ssh/id_rsa-cert type -1 debug1: identity file /home/yanue/.ssh/id_dsa type -1 debug1: identity file /home/yanue/.ssh/id_dsa-cert type -1 debug1: identity file /home/yanue/.ssh/id_ecdsa type -1 debug1: identity file /home/yanue/.ssh/id_ecdsa-cert type -1 debug1: identity file /home/yanue/.ssh/id_ed25519 type -1 debug1: identity file /home/yanue/.ssh/id_ed25519-cert type -1 ........

Finally, find the solution:

vi /etc/hosts.allow

Add:

sshd: ALL

Restart SSH and it’s OK

service sshd restart

SSH Error: (ssh: connect to host localhost port 22: Connection refused)

SSH: connect to host localhost port 22: connection reused

1.Problem description

I used to use the pagoda panel on the service before, but today I had a whim to use the pagoda panel on my computer. (the pagoda panel is really easy to use, especially for my ZZ little white)… But after installing the pagoda panel, when I started the terminal of the panel, I found that when I entered the SSH user name and password, there was no response, and the password and account number were clearly right

some people may want to ask, you TM use the pagoda panel on this machine, but also use the terminal of the pagoda, isn’t it unnecessary,, emmm is indeed, but I just like to do too much… Now that I find this problem, let’s try how to solve it

2. Problem solving

the possible reasons are: the port is not opened, the local firewall refuses, and the local machine has no SSH service

finally, the problem is that there is no SSH service on this machine, right! No, SSH is often used when you use Linux, but this machine may not have SSH service, so we need to install SSH service

generate SSH secret key

$ ssh-keygen -t rsa (Press enter evenly to generate the secret key)

$ cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys 

install openssh server (take Ubuntu operating system as an example)

$ sudo apt install openssh-server
 $ sudo /etc/init.d/ssh start 

Test

$ ps -ef | grep ssh(View sshd process)
 $ ssh 127.0.0.1

3. Success:

as shown in the figure:

if you have any questions, please leave a message, and you will help solve them when you see them

How to Fix Issue: SSH Server CBC Mode Ciphers Enabled

Because the project needs to be accepted for security detection, a security company has detected the following encryption vulnerabilities of sshd:
ssh server CBC mode ciphers enabled
warning: pay attention to check the status of sshd after restart
summary, description and solutions are as follows:
the security company has detected the following encryption vulnerabilities of sshd https://www.tenable.com/plugins/nessus/70658
1. Modify the encryption method

[root@localhost ~] vim /etc/ssh/sshd_config
Annotate related fields
# Ciphers and keying
Add encryption method at the end
Ciphers aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,arcfour
Macs hmac-sha1,hmac-ripemd160

2. Restart the service after saving

[root@localhost ~]# systemctl restart sshd

3. SSH verification

[root@localhost ~]# ssh -vv -oCiphers=aes128-cbc,3des-cbc,blowfish-cbc  target IP
[root@localhost ~]# ssh -vv -oMACs=hmac-md5  target IP

4. Nmap verification

nmap --script ssh2-enum-algos -sV -p 22  target IP

Results

Unable to negotiate with 127.0.0.1 port 22: no matching cipher found. Their offer: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,arcfour

Solve the problem of SSH Connection closed by foreign host

1. It is possible that the IP conflicts with others, just change the IP

2. There may also be file permissions. Change it:

cd /etc/ssh/ 
 chmod 600 ssh_host_* 
 chmod 644 *.pub

3. It may also be a firewall problem

/etc/init.d/iptables status     // Look at the firewall status first 
chkconfig iptables off        // Command to close

or:

#Stop firewall
systemctl stop firewalld.service

#Prohibit firewall startup
systemctl disable firewalld.service

 

Causes and solutions of system program problem detected in Ubuntu startup display

When using Ubuntu, you often encounter such an error prompt: “system program problem detected”

As shown in the figure:

Reason:

There is a built-in utility called app in Ubuntu, which can notify when a program crashes. This program, called import, notifies you of errors whenever you log into your Ubuntu system. It’s normal that you don’t have to panic or be afraid of such a mistake

Solution:

1. Inform system developers to do this. It’s recommended, and it won’t take you long. Click the “report prolem” button in the error prompt dialog box. You will be prompted to enter your administrator account password. Then, click “continue” to send the error prompt to developers, so that they can help solve the problem

First, make sure you are connected to the Internet properly. Once you submit the error report, developers will study the report carefully and try to solve the error in the next release

After submitting the error prompt, you can delete the file with the crash error prompt from your local system. If you want to see these error prompt files, you can enter the following command in the terminal: LS/var/crash/

Output (everyone is different)

libglib2.0-dev.0.crash_ usr_ bin_ appstreamcli.0.uploaded _ usr_ bin_ appstreamcli.0.crash _ usr_ bin_ pycompile.0.crash _ usr_ bin_ Appstreamcli. 0. Upload
delete all through the following command: sudorm – FR/var/crash/*

2. Disable the function of import. This is not recommended

Edit the app file/etc/default/APP

sudo nano /etc/default/apport

Find the line enabled=1 and change it to 0(zero)

# set this to 0 to disable apport, or to 1 to enable it

# you can temporarily override this with

# sudo service apport start force_start=1

enabled=0

Press crtl+x to exit, press y to save (nono), enter

Note: nano is a small, free and friendly editor. There are nano commands on most Linux

Then, you can stop the app service

Sudo stop apport

The app will not report any errors

Shell Syntax Error: operand expected (error token is “-”)

In this script for monitoring the real-time network port rate, there is an error on lines 21 and 22:

#!/bin/bash
#Modified by [email protected]
echo ===DTmobile NetSpeedMonitor===
sleep 1
echo loading...
sleep 1

ethn=$1
 
while true
do
  RXpre=$(cat /proc/net/dev | grep $ethn | sed 's/:/ /g' | awk '{print $2}')
  TXpre=$(cat /proc/net/dev | grep $ethn | sed 's/:/ /g' | awk '{print $10}')
  sleep 1
  RXnext=$(cat /proc/net/dev | grep $ethn | sed 's/:/ /g' | awk '{print $2}')
  TXnext=$(cat /proc/net/dev | grep $ethn | sed 's/:/ /g' | awk '{print $10}')
 
  clear
  echo -e "\t\t\t  RX \t\t   TX  \t\t\t TIME"
 
  RX=$((${RXnext}-${RXpre}))
  TX=$((${TXnext}-${TXpre}))
 
  if [ $RX -lt 1024 ];then
    RX="${RX}B/s"
  elif [ $RX -gt 1048576 ];then
    RX=$(echo $RX | awk '{print $1/1048576 "MB/s"}')
  else
    RX=$(echo $RX | awk '{print $1/1024 "KB/s"}')
  fi
 
  if [ $TX -lt 1024 ];then
    TX="${TX}B/s"
  elif [[ $TX -gt 1048576 ]];then
    TX=$(echo $TX | awk '{print $1/1048576 "MB/s"}')
  else
    TX=$(echo $TX | awk '{print $1/1024 "KB/s"}')
  fi
 
  echo -e "$ethn \t $RX   $TX   \t\t\t `date +%k:%M:%S` "
 
done

Revised document

#!/bin/bash
#Modified by [email protected]
echo ===DTmobile NetSpeedMonitor===
sleep 1
echo loading...
sleep 1

ethn=$1
 
while true
do
  RXpre=$(cat /proc/net/dev | grep $ethn | sed 's/:/ /g' | awk '{print $2}')
  TXpre=$(cat /proc/net/dev | grep $ethn | sed 's/:/ /g' | awk '{print $10}')
  sleep 1
  RXnext=$(cat /proc/net/dev | grep $ethn | sed 's/:/ /g' | awk '{print $2}')
  TXnext=$(cat /proc/net/dev | grep $ethn | sed 's/:/ /g' | awk '{print $10}')
 
  clear
  echo -e "\t\t\t  RX \t\t   TX  \t\t\t TIME"
 
  RX=$((RXnext-RXpre))
  TX=$((TXnext-TXpre))
 
  if [ $RX -lt 1024 ];then
    RX="${RX}B/s"
  elif [ $RX -gt 1048576 ];then
    RX=$(echo $RX | awk '{print $1/1048576 "MB/s"}')
  else
    RX=$(echo $RX | awk '{print $1/1024 "KB/s"}')
  fi
 
  if [ $TX -lt 1024 ];then
    TX="${TX}B/s"
  elif [[ $TX -gt 1048576 ]];then
    TX=$(echo $TX | awk '{print $1/1048576 "MB/s"}')
  else
    TX=$(echo $TX | awk '{print $1/1024 "KB/s"}')
  fi
 
  echo -e "$ethn \t $RX   $TX   \t\t\t `date +%k:%M:%S` "
 
done

The reason is that when the value of $is taken, only variables need to be followed in the brackets (variables can be calculated by themselves), and it is not necessary to take the value of variables in the brackets

RX=$((${RXnext}-${RXpre}))
  TX=$((${TXnext}-${TXpre}))
  
change to:
  
  RX=$((RXnext-RXpre))
  TX=$((TXnext-TXpre))

And then there’s no error~~~

How to Solve Syntax error: Bad for loop variable (ubuntu)

A simple shell script is written in Ubuntu, which uses for.. do.. done structure to calculate the value of 1 + 2 + 3… + 100, and the result always reports an error
script:
/ bin/bash
read -p “Please input a num ” num
sum=0
for ((a=0; a<=$ num; a=a+1))
do
sum=$(($sum + $a))
done
echo “the sum is ==> $ Sum ”
Exit 0

the error is syntax error: bad for loop variable
solution: sudo dpkg reconfiguration dash
select no from the options
from Ubuntu 6.10, Ubuntu will replace the previous default bash shell with dash shell; Instead of the traditional/bin/bash, the/bin/sh link reverses/bin/dash
Ubuntu edge is the first version to release dash as the default shell, which seems to be influenced by Debian. There’s an official explanation in the wiki, https://wiki.ubuntu.com/DashAsBinSh The main reason is that dash is smaller, faster and compatible with POSIX<However, the problem is that many scripts make mistakes due to the replacement of shell. After all, many scripts are not 100% POSIX compatible executing sudo dpkg reconfiguration dash on the terminal
and then selecting No