Tag Archives: linux

[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

GPG error:http://dl.google.com/linux/chrome/deb stable InRelease

0x00 problem description

	When updating apt sources with apt update today, it was exposed thatW: GPG error: http://dl.google.com/linux/chrome/deb stable InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 78BD65473CB3BD13

0x01 problem solving

	问The essence of the problem is that the public key 78BD65473CB3BD13 is missing, just add it.

0x02 specific steps

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys <PUBKEY>

[Solved] Ubuntu Terminal Error: subprocess installed post-installation script returned error exit status 1

An error occurred in the ubuntu terminal:subprocess installed post-installation script returned error exit status 1
An error occurred in the ubuntu terminal:subprocess installed post-installation script returned error exit status 1

An error occurred in the ubuntu terminal:subprocess installed post-installation script returned error exit status 1

System: Ubuntu 16.04

Error:

Use Command cd /sur/bin/dpkg/info

Folder usage: ls | grep ubuntu-advantage-tools*

The command to find the file with the error uses:sudo rm ubuntu-advantage-tools*
Delete is OK!

yum Error: error: db5 error(-30973) from dbenv->failchk: BDB0087 DB_RUNRECOVERY: Fatal error, run data……

1. On Linux server, execute the yum command and report an error as follows:
[root@isTester-Idoxu ~]# yum install nodejs
error: rpmdb: BDB0113 Thread/process 19512/140292738050112 failed: BDB1507 Thread died in Berkeley DB library
error: db5 error(-30973) from dbenv->failchk: BDB0087 DB_RUNRECOVERY: Fatal error, run database recovery
error: cannot open Packages index using db5 – (-30973)
error: cannot open Packages database in /var/lib/rpm
CRITICAL:yum.main:
Error: rpmdb open failed
2. Reason:
The rpm database is damaged.
3. Solution:
Just modify the database,
1)执行命令cd /var/lib/rpm
[root@isTester-Idoxu ~]# cd /var/lib/rpm
[root@isTester-Idoxu rpm]# ls
Basenames Conflictname __db.001 __db.002 __db.003 Dirnames Group Installtid Name Obsoletename Packages Providename Requirename Sha1header Sigmd5 Triggername
2) View
[root@isTester-Idoxu rpm]# ll
total 142484
-rw-r–r–. 1 root root 3051520 Nov 4 2020 Basenames
-rw-r–r–. 1 root root 16384 Oct 30 2020 Conflictname
-rw-r–r– 1 root root 286720 Nov 8 17:55 __db.001
-rw-r–r– 1 root root 90112 Nov 8 17:55 __db.002
-rw-r–r– 1 root root 1318912 Nov 8 17:55 __db.003
-rw-r–r–. 1 root root 2072576 Nov 4 2020 Dirnames
-rw-r–r–. 1 root root 20480 Nov 4 2020 Group
-rw-r–r–. 1 root root 16384 Nov 4 2020 Installtid
-rw-r–r–. 1 root root 36864 Nov 4 2020 Name
-rw-r–r–. 1 root root 16384 Nov 2 2020 Obsoletename
-rw-r–r–. 1 root root 136822784 Nov 4 2020 Packages
-rw-r–r–. 1 root root 1888256 Nov 4 2020 Providename
-rw-r–r–. 1 root root 253952 Nov 4 2020 Requirename
-rw-r–r–. 1 root root 73728 Nov 4 2020 Sha1header
-rw-r–r–. 1 root root 40960 Nov 4 2020 Sigmd5
-rw-r–r–. 1 root root 8192 Oct 30 2020 Triggername
3) Delete the damaged database file
[root@isTester-Idoxu rpm]# rm -rf __db.00*
[root@isTester-Idoxu rpm]# ll
total 140964
-rw-r–r–. 1 root root 3051520 Nov 4 2020 Basenames
-rw-r–r–. 1 root root 16384 Oct 30 2020 Conflictname
-rw-r–r–. 1 root root 2072576 Nov 4 2020 Dirnames
-rw-r–r–. 1 root root 20480 Nov 4 2020 Group
-rw-r–r–. 1 root root 16384 Nov 4 2020 Installtid
-rw-r–r–. 1 root root 36864 Nov 4 2020 Name
-rw-r–r–. 1 root root 16384 Nov 2 2020 Obsoletename
-rw-r–r–. 1 root root 136822784 Nov 4 2020 Packages
-rw-r–r–. 1 root root 1888256 Nov 4 2020 Providename
-rw-r–r–. 1 root root 253952 Nov 4 2020 Requirename
-rw-r–r–. 1 root root 73728 Nov 4 2020 Sha1header
-rw-r–r–. 1 root root 40960 Nov 4 2020 Sigmd5
-rw-r–r–. 1 root root 8192 Oct 30 2020 Triggername
4) Re-create the database file
[root@isTester-Idoxu rpm]# rpm –rebuilddb
[root@isTester-Idoxu rpm]# yum
Loaded plugins: fastestmirror, langpacks
You need to give some command
Usage: yum [options] COMMAND
List of Commands:
check Check for problems in the rpmdb
check-update Check for available package updates
clean Remove cached data
deplist List a package’s dependencies
distribution-synchronization Synchronize installed packages to the latest available versions
downgrade downgrade a package
erase Remove a package or packages from your system
fs Acts on the filesystem data of the host, mainly for removing docs/lanuages for minimal hosts.
fssnapshot Creates filesystem snapshots, or lists/deletes current snapshots.
groups Display, or use, the groups information
help Display a helpful usage message
history Display, or use, the transaction history
info Display details about a package or group of packages
install Install a package or packages on your system
langavailable Check available languages
langinfo List languages information
langinstall Install appropriate language packs for a language
langlist List installed languages
langremove Remove installed language packs for a language
list List a package or groups of packages
load-transaction load a saved transaction from filename
makecache Generate the metadata cache
provides Find what package provides the given value
reinstall reinstall a package
repo-pkgs Treat a repo. as a group of packages, so we can install/remove all of them
repolist Display the configured software repositories
search Search package details for the given string
shell Run an interactive yum shell
swap Simple way to swap packages, instead of using shell
update Update a package or packages on your system
update-minimal Works like upgrade, but goes to the ‘newest’ package match which fixes a problem that affects your system
updateinfo Acts on repository update information
upgrade Update packages taking obsoletes into account
version Display a version for the machine and/or available repos.
Options:
-h, –help show this help message and exit
-t, –tolerant be tolerant of errors
-C, –cacheonly run entirely from system cache, don’t update cache
-c [config file], –config=[config file]
config file location
-R [minutes], –randomwait=[minutes]
maximum command wait time
-d [debug level], –debuglevel=[debug level]
debugging output level
–showduplicates show duplicates, in repos, in list/search commands
-e [error level], –errorlevel=[error level]
error output level
–rpmverbosity=[debug level name]
debugging output level for rpm
-q, –quiet quiet operation
-v, –verbose verbose operation
-y, –assumeyes answer yes for all questions
–assumeno answer no for all questions
–version show Yum version and exit
–installroot=[path] set install root
–enablerepo=[repo] enable one or more repositories (wildcards allowed)
–disablerepo=[repo] disable one or more repositories (wildcards allowed)
-x [package], –exclude=[package]
exclude package(s) by name or glob
–disableexcludes=[repo]
disable exclude from main, for a repo or for
everything
–disableincludes=[repo]
disable includepkgs for a repo or for everything
–obsoletes enable obsoletes processing during updates
–noplugins disable Yum plugins
–nogpgcheck disable gpg signature checking
–disableplugin=[plugin]
disable plugins by name
–enableplugin=[plugin]
enable plugins by name
–skip-broken skip packages with depsolving problems
–color=COLOR control whether color is used
–releasever=RELEASEVER
set value of $releasever in yum config and repo files
–downloadonly don’t update, just download
–downloaddir=DLDIR specifies an alternate directory to store packages
–setopt=SETOPTS set arbitrary config and repo options
–bugfix Include bugfix relevant packages, in updates
–security Include security relevant packages, in updates
–advisory=ADVS, –advisories=ADVS
Include packages needed to fix the given advisory, in
updates
–bzs=BZS Include packages needed to fix the given BZ, in
updates
–cves=CVES Include packages needed to fix the given CVE, in
updates
–sec-severity=SEVS, –secseverity=SEVS
Include security relevant packages matching the
severity, in updates
Plugin Options:
5) Check whether the creation is successful
[root@isTester-Idoxu rpm]# ll
total 86052
-rw-r–r– 1 root root 2846720 Nov 8 17:58 Basenames
-rw-r–r– 1 root root 8192 Nov 8 17:58 Conflictname
-rw-r–r– 1 root root 286720 Nov 8 17:58 __db.001
-rw-r–r– 1 root root 90112 Nov 8 17:58 __db.002
-rw-r–r– 1 root root 57344 Nov 8 17:58 __db.003
-rw-r–r– 1 root root 1327104 Nov 8 17:58 Dirnames
-rw-r–r– 1 root root 24576 Nov 8 17:58 Group
-rw-r–r– 1 root root 16384 Nov 8 17:58 Installtid
-rw-r–r– 1 root root 40960 Nov 8 17:58 Name
-rw-r–r– 1 root root 16384 Nov 8 17:58 Obsoletename
-rw-r–r– 1 root root 81248256 Nov 8 17:58 Packages
-rw-r–r– 1 root root 1957888 Nov 8 17:58 Providename
-rw-r–r– 1 root root 217088 Nov 8 17:58 Requirename
-rw-r–r– 1 root root 69632 Nov 8 17:58 Sha1header
-rw-r–r– 1 root root 45056 Nov 8 17:58 Sigmd5
-rw-r–r– 1 root root 8192 Nov 8 17:58 Triggername
Done!

Popen error: cannot allocate memory [How to Solve]

 

Foreword

This is a bug found in the actual project. After the device runs for a period of time, an error is reported: Poppen error: cannot allocate memory. Operating platform: Xintang nuc970, memory 64M, Linux kernel version: 3.10.108 +.


1. Popen introduction

The Popen function creates a child process to execute Shell, and shell A sub process is created to execute commands. From the practice process, it can be seen that after the process allocates memory and fills the process stack space, these functions fail to execute and return enomem error code cannot allocate memory. As long as the space is not released, the execution fails all the time

2. Cause analysis of Popen error

Here is a test program to reproduce the problem: the main thread malloc applies for heap space and fills the stack space of the process; Another thread performs the Popen operation. The result is that when the routine thread executes Popen, it always reports a Popen error: cannot allocate memory error until the main thread executes the free operation.

1. System memory of the device

2. Run the test program./test  , Max statck size is just 8m

3. Results: when the process is running, an error is reported when the heap space exceeds 8m, but in fact, the memory in the system is still sufficient, with more than 37m.

4. Once the space requested by malloc is released, it will return to normal immediately

5. Test program source code

#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <pthread.h>
#include <stdlib.h>
#include <sys/sysinfo.h>

#define SIZE (1024*1024*1)
#define MEM_SIZE (45)

void *routine(void *arg)
{
	struct sysinfo info;
	
	while(1)
	{		
		sysinfo(&info);
		printf("freeram = %ld\n",info.freeram);
		
		FILE* fp = popen("cat /sys/class/net/eth0/carrier", "r");
		if(fp == NULL)
		{
			printf("popen error:%s\n", strerror(errno));
			sleep(1);
			continue;
		}
		
		char  buffer[1024];
		int   bytes_read = fread(buffer, 1, sizeof(buffer), fp);
		pclose(fp);

		printf("popen ok %2x\n",buffer[0]);			
		sleep(1);
		
	}
}

int main(int argc, char **argv)
{
		
	pthread_t tid;
	pthread_create(&tid, NULL, routine, NULL);
	

	unsigned int *p = (unsigned int *)malloc(1024 * 1024 * MEM_SIZE);
	printf("malloc buffer: %p\n", p);

	for (int i = 0; i < 1024 * 1024 * (MEM_SIZE/sizeof(int)); i++) 
	{
		p[i] = 123;
		if ((i & 0xFFFFF) == 0) 
		{
			printf("%dMB written\n", i >> 18);
			sleep(1);
			//usleep(100000);
		}

	}

	
	while(1)
	{
		sleep(20);
		if(p)
		{
			printf("free mem\n"); //The popen call is normal after the memory is released
			free(p);
			p = NULL;
		}
	}
	
	return 0;
}

Summary

The system overhead of functions such as Popen is very high. When the process memory is tight, it is easy to make mistakes. If the requested memory space is not released in time, the execution fails all the time.

ERROR: configuration failed for package ‘openssl’ [How to Solve]

ERROR: configuration failed for package ‘openssl’
removing ‘/usr/local/lib/R/site-library/openssl’
The ubuntu system lacks openssl:

apt-get install openssl
apt-get install openssl-devel

Or:

wget https://www.openssl.org/source/openssl-1.1.1i.tar.gz

tar -xvf  openssl-1.1.1i.tar.gz

cd openssl-1.1.1i/

./config 

make && make install

./config shared 

make clean

make  && make install

[Solved] C++: fatal error: Killed signal terminated program cc1plus

[problem solving] C + +: fatal error: killed signal terminated program cc1plus

1. Problem description

During C + + compilation in Linux system, the following errors occur, resulting in compilation abort:

C++: fatal error: Killed signal terminated program cc1plus
compilation terminated.

2. Solution – swap partition

After consulting the relevant information, it is considered that the virtual machine is caused by insufficient memory. This problem is solved by creating swap partition, and the compilation is successful
the following is a summary of the creation and activation of swap partitions:

# Create the partition path
sudo mkdir -p /var/cache/swap/
# Set the size of the partition
# bs=64M is the block size, count=64 is the number of blocks, so the swap space size is bs*count=4096MB=4GB
sudo dd if=/dev/zero of=/var/cache/swap/swap0 bs=64M count=64
# Set permissions for this directory
sudo chmod 0600 /var/cache/swap/swap0
# Create the SWAP file
sudo mkswap /var/cache/swap/swap0
# Activate the SWAP file
sudo swapon /var/cache/swap/swap0
# Check if SWAP information is correct
sudo swapon -s

The effect diagram of partition creation and activation is as follows:

The path of the swap 0 file is under/var/cache/swap/. After compilation, if you don’t want to swap partitions, you can delete it.

Command to delete swap partition:

sudo swapoff /var/cache/swap/swap0
sudo rm /var/cache/swap/swap0

Free space command:

sudo swapoff -a
#Detailed usage: swapoff --help
#View current memory usage: --swapoff: free -m

[docker][issue]Error response from daemon: mkdir xxx: file exists: unknown

Problem Description:
after the docker is closed abnormally, the following error is reported when starting the container:

linux> Error response from daemon: mkdir /run/containerd/io.containerd.runtime.v1.linux/moby/189aafa489967asdf23664d32f9e33e121a7b3b6e789d8642345678dfg6ebe13cb: file exists: unknown
linux> Error: failed to start containers: asdf

Solution:

# excute
linux> ps aux | grep 189aafa489967asdf23664d32f9e33e121a7b3b6e789d8642345678dfg6ebe13cb
# output
linux> root      6358  0.0  0.0 108748  4136 ?       Sl   Oct27   1:50 containerd-shim -namespace moby -workdir /var/lib/containerd/io.containerd.runtime.v1.linux/moby/189aafa489967asdf23664d32f9e33e121a7b3b6e789d8642345678dfg6ebe13cb -address /run/containerd/containerd.sock -containerd-binary /usr/bin/containerd -runtime-root /var/run/docker/runtime-nvidia
# Kill off and restart the container
kill 6358

ERROR: dependencies ‘curl’, ‘openssl’ are not available for package ‘httr’

ERROR: dependencies ‘curl’, ‘openssl’ are not available for package ‘httr’
removing ‘/usr/local/lib/R/site-library/httr’

apt-get install openssl
apt-get install openssl-devel

apt-get install libcurl

Or:

wget https://www.openssl.org/source/openssl-1.1.1i.tar.gz

tar -xvf  openssl-1.1.1i.tar.gz

cd openssl-1.1.1i/

./config 

make && make install

./config shared 

make clean

make  && make install

‘curl’:

wget  http://curl.haxx.se/download/curl-7.38.0.tar.gz

tar -xzvf curl-7.38.0.tar.gz

cd curl-7.38.0

./configure

make

make install