Category Archives: Linux

[Solved] Linux Mongodb Error: # Error: coul-bash: connecting: command not found

1. MongoDB error content and solution
This is an error when entering mongo startup

[root@g3dhkzznakmqafv5-1029528 mongodb]# Error: coul-bash: connecting: command not found
.1:27017 :: caused by :: Connection refused :ction attempt failed: SocketException: Error connecting to 127.0.0
[1]+ Exit 127 connecting to: mongodb://127.0.0.1:27017/?compressors=disabled
connect@src/mongo/shell/mongo.js:374:17
@(connect):2:6
exception: connect failed
exiting with code 1
Change the permission of .sock file.

Next, we check the error report of the MongoDB log

"ctx":"SignalHandler","msg":"Shutdown: going to close listening sockets"}
{"t":{"$date":"2021-11-14T21:50:59.901+08:00"},"s":"I",  "c":"NETWORK",  "id":23017,   "ctx":"listener","msg":"removing socket file","attr":{"path":"/tmp/mongodb-27017.sock"}}
{"t":{"$date":"2021-11-14T21:50:59.901+08:00"},"s":"I",  "c":"NETWORK",  "id":4784905, "ctx":"SignalHandler","msg":"Shutting down the global connection pool"}

Solution:

The above log has said to remove mongodb-27017.sock in the/tmp directory
here, you can switch to the TMP directory to view the mongodb-xxx.sock file
remove the mongodb-27017.sock file, and then restart OK successfully
if you have tried to switch ports, remove all mongodb-xxx.sock files

[Solved] Nvml compilation official use case error: collect2: error: ld returned 1 exit status

Question

When running the example of nvml, an error is reported:

/tmp/tmpxft_00001d31_00000000-4_gpu_monitor.o: In the function ‘main’:
gpu_monitor.c:(.text+0x77): undefined reference to ‘nvmlInit_v2’
gpu_monitor.c:(.text+0x93): undefined reference to ‘nvmlErrorString’
gpu_monitor.c:(.text+0xcd): undefined reference to ‘nvmlDeviceGetCount_v2’
gpu_monitor.c:(.text+0xe9): undefined reference to ‘nvmlErrorString’
gpu_monitor.c:(.text+0x15e): Undefined reference to ‘nvmlDeviceGetHandleByIndex_v2’
gpu_monitor.c:(.text+0x17a): undefined reference to ‘nvmlErrorString’
gpu_monitor.c:(.text+0x1b4): undefined reference to ‘nvmlDeviceGetName’
gpu_monitor.c:(.text+0x1d0): undefined reference to ‘nvmlErrorString’
gpu_monitor.c:(.text+0x208): Undefined reference to ‘nvmlDeviceGetPciInfo_v3’
gpu_monitor.c:(.text+0x224): undefined reference to ‘nvmlErrorString’
gpu_monitor.c:(.text+0x282): undefined reference to ‘nvmlDeviceGetComputeMode’
gpu_monitor.c:(.text+0x2b6): undefined reference to ‘nvmlErrorString’
gpu_monitor.c:(.text+0x318): undefined reference to ‘nvmlDeviceSetComputeMode’
gpu_monitor.c:(.text+0x334): undefined reference to ‘nvmlErrorString’
gpu_monitor.c:(.text+0x379): undefined reference to ‘nvmlErrorString’
gpu_monitor.c:(.text+0x3ce): undefined reference to ‘nvmlDeviceSetComputeMode’
gpu_monitor.c:(.text+0x3ea): undefined reference to ‘nvmlErrorString’
gpu_monitor.c:(.text+0x423): Undefined reference to ‘nvmlDeviceGetPowerUsage’
gpu_monitor.c:(.text+0x43f): undefined reference to ‘nvmlErrorString’
gpu_monitor.c:(.text+0x4a4): undefined reference to ‘nvmlShutdown’
gpu_monitor.c:(.text+0x4c0): undefined reference to ‘nvmlErrorString’
collect2: error: ld returned 1 exit status

Solution:

At the beginning, the above error occurs when compiling with the command nvcc – O example.C example.
compile successfully with the command nvcc – I – L/usr/lib – lnvidia ml example.C – O example

Git Error: remote: HTTP Basic: Access denied [How to Solve]

reason:

The user name and password configured by local git are inconsistent with those registered on gitlab.

Solution:

If the account and password are changed, execute the following commands on the GIT command line

git config --system --unset credential.helper

Then re execute your operations (such as pull and push), and you will be prompted to enter your account and password again.

What’s your feeling?

In retrospect, it seems that I did create a new user name and password, or I changed my password. ok

[Solved] git error – remote: http basic: access denied

After using the git push command, an error is reported as follows:

another error is:

git Failed to connect to port xxxx: Connection refused

based on these two situations, the account and password logged in at the time of the first use are largely inconsistent with the current warehouse account password, so the user will be prompted to connect without permission or refuse access. At this time, the best way is to reset the GIT account password!

Solution:

first enter the local warehouse directory, then right-click “git bash here”, and enter the following instructions in the pop-up terminal input box:

git config --system --unset credential.helper

Then use the git push command again to guide you to enter the account and password again. After you enter it correctly, you can connect to the remote warehouse successfully!!

[Solved] Linux — 9 — txt files are copied from windows to Linux and read error

Reason: different coding methods

Solution:

Modify the CFG configuration file in Linux, create a new CFG text file, copy and paste it into the new CFG. File file name to view the encoding method of the file.

How to convert in Linux?

Convert CFG files in folders 1 and 2 [UTF-8 (with BOM) to UTF-8]:

#!/bin/bash

function cfg_change()
{
	dir=./etc/xxx/"$1"/
	find $dir -type f -name "cfg.txt" -print | xargs -i sed -i '1 s/^\xef\xbb\xbf//' {}
	echo "-------Convert Succeed-------"
	file ./etc/xxx/"$1"/cfg.txt
}

case "$1" in
	-1)
		cfg_change 1;
    ;;
	-2)
		cfg_change 2;
	;;
	*)
		echo "Usage: $0 -1|-2"
esac

exit 0

Kali starts SSH service error [How to Fix]

Kali starts SSH service and resolves error reports

1. Open the SSH configuration file (remember sudo)

sudo vim /etc/ssh/sshd_config

2. #permitrotlogin is changed to

PermitRootLogin yes

That is, remove #, and change the proposal password to yes
3. #passwordauthentication line to

PasswordAuthentication yes

4. Enter after saving and exiting

sudo /usr/sbin/sshd

Errors may be encountered

Missing privilege separation directory: /run/sshd

Solution:

sudo mkdir /run/sshd

Linux: How to Solve sudo operate Error

Here, I need to install a driver on the server. When using sudo command, the following error is reported
XXX (user name) is not in the sudoers file. This incident will be reported.
it should be noted that my user is not a super administrator user, but a new ordinary user developed by the super administrator user, The reason why the above error is reported is that this user is an ordinary user and does not have operation permissions on the operating system. Here, the super administrator needs to add top-level permissions to ordinary users in the configuration file sudoers. The operations are as follows:

1. Switch to root, directly enter Su in terminator, and then prompt for the password. The password here is the login password of super administrator

2. The/etc/sudoers file is read-only by default for all users (including the root user), so you need to add write permission to the sudoers file. The command is: CHMOD U + W/etc/sudoers

3. Edit the sudoers file VI/etc/sudoers
the sudoers file is as follows
find this line root all = (all) all, and add XXX all = (all) all (XXX here is your user name)

PS: Here you can add any of the following four lines to sudoers

youuser ALL=(ALL) ALL
%youuser ALL=(ALL) ALL
youuser ALL=(ALL) NOPASSWD: ALL
%youuser ALL=(ALL) NOPASSWD: ALL

Line 1: allow user youuser to execute sudo command (password required).
line 2: allow users in user group youuser to execute sudo command (password required).
line 3: allow user youuser to execute sudo command without entering password.
line 4: allow users in user group youuser to execute sudo command, And do not enter the password when executing

4. Revoke sudoers file write permission. Command:

chmod u-w /etc/sudoers

Linux: How to Solve Rabbitmq Plug-in Install Error

After rabitmq is installed normally, rabbitmq server starts normally, but rabbitmq_ The management plug-in failed to start and reported an error:

rabbitmq-plugins enable rabbitmq_management
{:query, :rabbit@web101, {:badrpc, :timeout}}

Solution:
add the Linux host number and host name at the end of the hosts file
method: VI/etc/hosts
Edit by I
host number host name
for example: 192.168.1.1 localhost (fill in your own here)
after adding: WQ save exit
at this time, you can view the rabbitmq plug-in

After rabbitmq is started and the plug-in is also enabled, the page cannot be accessed
the firewall may not be closed

Solution: turn off the Linux firewall

(1) Set boot enable firewall: systemctl enable firewalld.service

(2) Set boot disable firewall: systemctl disable firewalld.service

(3) Start firewall: systemctl start firewalld

(4) Turn off the firewall: systemctl stop firewalld

(5) Check firewall status: systemctl status firewalld

[Solved] Ubuntu Open jpg Image Error: Error interpreting JPEG image file (Not a JPEG file: starts with 0x89 0x50)

Question

The Java background receives a JPG format picture and finds that it can be opened and displayed normally under windows, but when it is opened under Ubuntu, it prompts error interpreting JPEG image file (not a JPEG file: starts with 0x89 0x50) . As shown in the following figure:

prompt that the file is not a JPEG image file, and the first two bytes of the file are 0x89 and 0x50 respectively.

Solution:

Via Wikipedia list_of_file_Signatures learned that the file signature at the beginning of these two bytes should be in PNG file format. Change the file suffix to PNG, and then open the file to display normally

for this reason, the logic for judging the file signature is added in the background interface to prevent the suffix submitted by the front end from being not the real format of the file (not limited to pictures).

For malicious files that deliberately forge file header information, the following logic cannot play a screening role.

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class filetools
{
	public final static Map<String, String> FILE_TYPE_MAP = new HashMap<String, String>();

	static
	{
		getAllFileType();
	}

	private static void getAllFileType()
	{
		FILE_TYPE_MAP.put("jpg(JFIF)", "^FFD8FFE000104A4649460001"); // jpg JFIF file format
		FILE_TYPE_MAP.put("jpg(Exif)", "^FFD8FFE1.{4}457869660000"); // jpg Exif file format
		FILE_TYPE_MAP.put("jpeg", "^FFD8FFEE"); // jpeg
		FILE_TYPE_MAP.put("png", "^89504E470D0A1A0A"); // PNG (png)
		FILE_TYPE_MAP.put("bmp", "^424D"); // Windows Bitmap (bmp)
		FILE_TYPE_MAP.put("mp4", "^000000206674797069736F6D"); // ISO Base Media file (MPEG-4)
	}

	public final static String getFileByFile(File file)
	{
		String filetyp = null;
		byte[] fileheader = new byte[15]; 
		try
		{
			InputStream is = new FileInputStream(file);
			is.read(fileheader);
			filetyp = getFileTypeByStream(fileheader);
			is.close();
		} catch (FileNotFoundException e)
		{
			e.printStackTrace();
		} catch (IOException e)
		{
			e.printStackTrace();
		}
		return filetyp;
	}

	public final static String getFileTypeByStream(byte[] b)
	{
		String filetypeHex = String.valueOf(getFileHexString(b));
		Iterator<Entry<String, String>> entryiterator = FILE_TYPE_MAP.entrySet().iterator();
		while (entryiterator.hasNext())
		{
			Entry<String, String> entry = entryiterator.next();
			String fileTypeHexValue = entry.getValue();
			Pattern p = Pattern.compile(fileTypeHexValue);
			Matcher m = p.matcher(filetypeHex.toUpperCase());

			if (m.find())
			{
				if (0 == m.start()) 
					return entry.getKey();
			}
		}
		return "unknow type";
	}

	public final static String getFileHexString(byte[] b)
	{
		StringBuilder stringBuilder = new StringBuilder();
		if (b == null || b.length <= 0)
		{
			return null;
		}
		for (int i = 0; i < b.length; i++)
		{
			int v = b[i] & 0xFF;
			String hv = Integer.toHexString(v);
			if (hv.length() < 2)
			{
				stringBuilder.append(0);
			}
			stringBuilder.append(hv);
		}
		return stringBuilder.toString();
	}

	public static void main(String[] args)
	{
		File f = new File("/home/alderaan/111.jpg");
		if (f.exists())
		{
			String filetype = getFileByFile(f);
			System.out.println(filetype);
		} else
		{
			System.out.println(f.getPath() + " not found!");
		}
	}
}