리눅스 서버는 /etc/machine-id 라는 파일이 있다. 해당 파일은 machine의 고유 아이디값을 랜덤하게 생성하여 저장된 것으로 32글자로 된 16바이트/128비트 의 UUID값이다.

 machine-id는 dbus 또는 systemd 동작에 관련되어 있으며 /etc/machine-id 는 기본적으로 /var/lib/dbus/machine-id 에 심볼릭 링크되어있는 경우도 있다.

일단 해당 파일이 없는경우 어떤 문제가 일어나는지 알아보자

[    2.680252] systemd[1]: Inserted module 'ip_tables'
[    3.751916] systemd-journald[665]: Failed to get machine id: No such file or directory
[    3.755044] systemd-journald[677]: Failed to get machine id: No such file or directory
[    3.757980] systemd-journald[678]: Failed to get machine id: No such file or directory
[    3.760862] systemd-journald[679]: Failed to get machine id: No such file or directory
[    3.763454] systemd-journald[680]: Failed to get machine id: No such file or directory
[    4.023763] systemd-tmpfiles[676]: [/usr/lib/tmpfiles.d/systemd.conf:26] Failed to replace specifiers: /run/log/journal/%m
[    4.023804] systemd-tmpfiles[676]: [/usr/lib/tmpfiles.d/systemd.conf:28] Failed to replace specifiers: /run/log/journal/%m
[    4.023838] systemd-tmpfiles[676]: [/usr/lib/tmpfiles.d/systemd.conf:29] Failed to replace specifiers: /run/log/journal/%m
[    4.023873] systemd-tmpfiles[676]: [/usr/lib/tmpfiles.d/systemd.conf:32] Failed to replace specifiers: /var/log/journal/%m
[    4.023910] systemd-tmpfiles[676]: [/usr/lib/tmpfiles.d/systemd.conf:33] Failed to replace specifiers: /var/log/journal/%m/system.journal
[    4.031224] systemd-tmpfiles[676]: [/usr/lib/tmpfiles.d/systemd.conf:37] Failed to replace specifiers: /var/log/journal/%m
[    4.031259] systemd-tmpfiles[676]: [/usr/lib/tmpfiles.d/systemd.conf:38] Failed to replace specifiers: /var/log/journal/%m
[    4.031292] systemd-tmpfiles[676]: [/usr/lib/tmpfiles.d/systemd.conf:39] Failed to replace specifiers: /var/log/journal/%m/system.journal

시스템의 dmesg내용을 보면 위와같은 항목이 나타나게 된다. 이것은 systemd가 부팅시 machine-id 를 읽어 관련 동작을 초기화하는데 있어 machine-id값이 없어서 나는 오류메시지 이다.
파일이 없으면 자동으로 생성하면 되는게 아닌가 싶은데 일단 파일이 없는경우 자동생성되지 않고 위와같이 오류메세지가 나타난다.

또한 이 오류로 인해 systemd 관련 로그가 생성되지 않는다. 즉 대부분의 /var/log/에 쌓이는 로그들이 정상적으로 기록되지 않는다.

해결법

위 증세를 해결하기 위해서는 반드시 /etc/machine-id라는 파일이 존재하여야 한다.
두가지 방법이 있는데 아래를 참조하면 된다.

  • systemd-machine-id-setup 이용하는 방법
rm -f /etc/machine-id /var/lib/dbus/machine-id
systemd-machine-id-setup
  • dbus-uuidgen 사용법
rm -f /etc/machine-id /var/lib/dbus/machine-id
dbus-uuidgen --ensure=/etc/machine-id
dbus-uuidgen --ensure

시스템 재부팅 할 것~!

출처 : https://atl.kr/dokuwiki/doku.php/machine-id

  • 리눅스 history 날짜/시간 적용 방법

history에 날짜/시간을 적용하는 방법 자체도 매우 쉽고, 사용 하다보면 history에 날짜/시간이 적용되지 않아 history를 추적하기 힘든 상황이 발생할 수 있기 때문에 되도록 history에는 날짜와 시간을 적용하여 사용하는것이 좋습니다.

아래와 같이 /etc/profile 파일을 vi 편집기로 열은 후 맨 마지막 줄에 HISTTIMEFORMAT="[%Y-%m-%d_%H:%M:%S]  " 를 넣어주면 끝 입니다.

vi /etc/profile

# 맨 마지막 줄로 이동하여 아래 내용 기입
HISTTIMEFORMAT="[%Y-%m-%d_%H:%M:%S]  "
:wq

또는 아래와 같이 한줄로 간단하게 적용할 수 있습니다.

echo "HISTTIMEFORMAT=\"[%Y-%m-%d_%H:%M:%S]  \"" >> /etc/profile

적용 후 원격터미널을 로그아웃 후 재접속한 뒤 history 명령을 실행하면 입력했던 명령어 앞에 날짜와 시간이 나오는 것을
확인할 수 있다.

출처 : https://nirsa.tistory.com/234

리눅스 sendmail "unable to qualify my own domain name (YOUTHOSTNAME) unknown; sleeping for retry" 발생 시

보통 서버의 호스트네임을 localhost 말고 다른걸로 변경하여 사용할 때 발생 하는데, 서비스 시작이 굉장히 느리게 되거나 안되는 경우가 안되기도 합니다.

"unable to qualify my own domain name (YOUTHOSTNAME) unknown; sleeping for retry" 에러가 발생하면 hosts 파일에 127.0.0.1으로 서버의 호스트 네임을 작성 해주시면 됩니다.

hostname이 antamis 일 경우

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4  antamis
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

 

출처 : https://nirsa.tistory.com/315

서버에서 파일명이 깨지는 경우 인코딩 변경으로 문제를 해결할 수 있는 명령어이다.
이종간의 OS (예 : 윈도우와 MAC) 에서 주로 발생하는데
윈도우는 EUC-KR이 기본 인코딩이고 MAC은 UTF-8이 기본 인코딩이라 MAC에서 FTP등을 통해 한글파일이나 폴더를
업로드할 경우 인코딩이 깨진채로 업로드된다.
이런 경우 convmv라는 유용한 명령어가 있는데 명령어가 없다면 아래 명령어로 설치한다.
(CentOS 또는 RockyLinux) yum install convmv

폴더로 들어가서 처리를 할 경우 아래와 같이 명령어를 선택하면 해당 폴더에 있는 euc-kr 인코딩이 utf-8 인코딩 방식으로 바뀐다.

[EUC-KR → UTF-8]

convmv -f euc-kr -t utf-8 ./*.* --notest

[UTF-8 → EUC-KR]

convmv -f utf-8 -t euc-kr ./*.* --notest

여기서 --notest 를 입력하지 않을 경우 인코딩 방식은 바뀌지 않고,  어떻게 변경되는지만 확인할 수 있다.

참고로 현재 위치에서 하위 디렉토리까지 포함하여 인코딩 방식을 변경하기 위해서는 -r 옵션을 추가하면 된다.

convmv -f euc-kr -t utf-8 ./*.* -r --notest

특정파일 1개만 변경할 때는 아래와 같이 처리한다.

convmv --notest --replace -r -f euc-kr -t utf-8 FileName

--replace 옵션은 동일한 파일명으로 덮어쓰기 하고 싶을 때 추가

터미널에서 인터넷 속도 측정이 하고 싶어서 조사해본 내용 정리.

설치

https://www.speedtest.net/ko/apps/cli

sudo apt-get install speedtest로 설치하면 서버 목록이 10개밖에 안 되는 비공식 버전을 받게 된다. 그러므로 다음과 같이 설치하자.

혹시 이미 비공식 버전을 설치했다면, 위 공식사이트 링크의 주석을 따라 삭제하는 절차를 밟도록 하자.

[맥OS]

brew tap teamookla/speedtest
brew update
brew install speedtest --force

[리눅스 데비안(우분투) 계열]

curl -s https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh | sudo bash
sudo apt-get install speedtest

[리눅스 레드햇 계열]

curl -s https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.rpm.sh | sudo bash
sudo yum install speedtest

실행 방법은 간단하다. 실행하고 yes를 입력해 라이센스에 동의한다.

speedtest

결과

   Speedtest by Ookla

      Server: Ookla - Seoul (id: 5249)
         ISP: Lg Powercomm
Idle Latency:    10.36 ms   (jitter: 0.64ms, low: 9.57ms, high: 11.03ms)
    Download:   876.93 Mbps (data used: 797.8 MB)                                                   
                 77.18 ms   (jitter: 7.83ms, low: 8.93ms, high: 133.85ms)
      Upload:   866.89 Mbps (data used: 725.8 MB)                                                   
                  8.80 ms   (jitter: 0.54ms, low: 7.42ms, high: 10.87ms)
 Packet Loss:     0.0%
  Result URL: https://www.speedtest.net/result/c/c0c219c5-eeea-471d-8f99-188844c7a165

출처 : https://velog.io/@jay6768/%ED%84%B0%EB%AF%B8%EB%84%90%EC%97%90%EC%84%9C-%EB%84%A4%ED%8A%B8%EC%9B%8C%ED%81%AC-%EC%86%8D%EB%8F%84-%EC%B8%A1%EC%A0%95-speedtest-cli

ls -l 출력 시 날짜 변경( 12월  2009 -> 2009-07-01 08:35 )

변경 전

[root@wooseob ~]# ls -l
-rw------- 1 root root  1104 12월 17 03:22 anaconda-ks.cfg
-rw-r--r-- 1 root root 25690 12월 17 03:22 install.log
-rw-r--r-- 1 root root  4508 12월 17 03:21 install.log.syslog

# alias ls='ls --color=auto --time-style=long-iso'          날짜표시 변경하는 명령어

변경 후

[root@wooseob ~]# ls -l
-rw------- 1 root root  1104 2012-12-17 03:22 anaconda-ks.cfg
-rw-r--r-- 1 root root 25690 2012-12-17 03:22 install.log
-rw-r--r-- 1 root root  4508 2012-12-17 03:21 install.log.syslog

 

개인 사용자(~/.bashrc 기재)

[root@wooseob ~]# vi ~/.bashrc
# .bashrc

# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias ls='ls --color=auto --time-style=long-iso'       -  추가 입력

전체 사용자 적용 시

[root@wooseob ~]# vi /etc/bashrc
# /etc/bashrc

# System wide functions and aliases
# Environment stuff goes in /etc/profile

alias ls='ls --color=auto --time-style=long-iso'        -  추가 입력

출처 : https://faq.hostway.co.kr/Linux_ETC/4495

$ scp -P [port] [보낼파일] xxx@[ip addr]:~
ex) scp -P 22 test.txt abc@11.22.33.44

위의 명령을 통해 scp를 수행했는데 아래와 같은 에러가 떴다.

subsystem request failed on channel 0
scp: Connection closed

-O 옵션을 추가해주면 문제가 해결된다.

$ scp -O -P 22 test.txt abc@11.22.33.44

출처 : https://me74.tistory.com/130

vi, vim ^M 제거


윈도우에서 작성한 파일을 Unix/Linux상에 올리면 개행 문자가 깨져서 ^M가 보이는 경우를 봤을 것이다.이것은 윈도우에서는 CRLF 가 개행인데 Linux/Unix에서는 LF가 개행이라 나타나는 현상으로 보면 된다.

[CR,LF 뜻]

라인피드(LF : Line Feed) => 현재 위치에서 바로 아래로 이동

캐리지리턴(CR: Carriage return) => 커서의 위치를 앞으로 이동

설명은 이정도로 하고 제거 방법을 알아 보자

vi, vim에서 제거 하는 방법

결론부터 말하면 다음과 같이 하면 된다.

:%s/^M//g

위에서 ^M는 ^+M 이 아니고 Ctrl + v + m 이다.

vi에서 입력한 각 명령어에 대해 설명 하겠다.

:                 --> vi,vim에서 명령어를 입력 하겠다는 신호
:%s            --> 문자열을 치환하겠다는 명령어
:%s/^M      --> ^M 문자열을 치환하겠다
:%s/^M//    --> ^M 문자열을 공백으로 치환하겠다.
:%s/^M//g  --> 해당 문서 전체 ^M 문자열을 공백으로 치환하겠다.

 

윈도우에서 Unix/Linux로 파일 올릴때 ^M 안생기게 하는 방법

운영체제 마다 줄바꿈 정의가 다르다. 

각 운영체제 마다 정의를 살펴 보자.

윈도우/DOS : CRLF 조합으로 줄바꿈을 정의
Unix/Linux/C : LF 만으로 줄바꿈을 정의

이래서 윈도우에서 작성 된 것을 Unix/Linux 계열로 올리면 vi로 편집했을 때 ^M이 붙는 것을 확인 할 수 있다.

물론 ftp로 올릴 때 방식이 텍스트/2진 어떤 것을 선택하느냐에 따라 달라질 수 있다.

텍스트 방식으로 올리면 데이터 변환이 생겨 /r/n -> /n 으로 된다. 

2진 모드로 올릴때는 변환이 생기지 않아 윈도우에서 작성된 파일이 컴파일이 안되거나 script작성 된것이 동작 안할 수가 있다.

[sftp 전송 방식]
텍스트 방식 : 줄바꿈에 대한 변환이 일어남
2진 모드 : 줄바굼에 대한 변환이 일어나지 않음 ( 문제가 발생할 수 있다. )

출처: https://jink1982.tistory.com/123 [돼민이:티스토리]

RockyLinux8 (CentOS8) 이상부터는 파일명에 공백이나 특수문자가 포함된 경우 파일명이 작은 따옴표로 감싸지는 현상이 있다.

이 따옴표가 매우 걸리적거려 해결방법을 검색하다가 해외포럼에서 해결책을 찾게 되었다. 아래는 그 내용에 대한 정리다.

[원문]
This was a highly unpopular feature introduced to version 8.25 of the GNU coreutils package as recently as 2016, by a consensus of just three developers.

Arguments cited by critics of the change include that it makes the output of ls look considerably more unsightly, unnecessarily diverges from nearly half a century of Unix tradition, and due to the way it was implemented (opt-out instead of opt-in) breaks compatibility with long-standing existing scripts and utilities.

Because the feature was introduced to the coreutils package - which virtually every Linux distribution depends on and which ls is a part of - the change affects every Linux or Linux-like system imaginable, from Arch Linux to Cygwin.

In the case of Debian and Debian-derived distros like Ubuntu, the change was at some point reverted after considerable protest, before being once again reinstated in October 2017.

As this answer makes clear, the best way to register your disappointment at this change would be to contact the coreutils developers directly via a bug report and (politely) make the argument that they've made a huge mistake. As per the open source ethos, a critical mass of users respectfully but adamantly insisting that the way ls used to behave be properly reinstated should in theory be enough to convince the coreutils developers to listen to the Linux community.

[번역]
이것은 단지 3명의 개발자들의 합의에 의해 2016년까지만 해도 GNU 코어유틸스 패키지 버전 8.25에 도입된 매우 인기 없는 기능이었습니다.

이러한 변화에 대한 비평가들이 인용한 주장으로는 ls의 출력을 훨씬 더 보기 흉하게 만들고, 거의 반세기에 걸친 유닉스 전통과 불필요하게 괴리가 있으며, 구현 방식으로 인해 (opt-in 대신 opt-out) 오래된 기존 스크립트 및 유틸리티와의 호환성이 깨진다는 것 등이 있습니다.

이 기능은 사실상 모든 리눅스 배포판이 의존하고 어떤 ls가 속해 있는지에 따라 결정되는 코어유틸리티 패키지에 도입되었기 때문에, 이러한 변화는 Arch Linux에서 Cygwin에 이르기까지 상상할 수 있는 모든 Linux 또는 Linux와 유사한 시스템에 영향을 미칩니다.

우분투와 같은 데비안 및 데비안 파생 디스트로의 경우 상당한 항의 끝에 변경이 어느 정도 번복되었다가 2017년 10월에 다시 복원되었습니다.

이 답변이 분명히 밝힌 바와 같이, 이러한 변화에 대한 실망감을 등록하는 가장 좋은 방법은 버그 보고서를 통해 코어유틸리티 개발자들에게 직접 연락하여 (정중하게) 그들이 큰 실수를 저질렀다고 주장하는 것입니다. 오픈 소스의 기풍에 따르면, 이론적으로 이전에 행동했던 방식이 적절하게 복원되어야 한다고 주장하는 사용자들의 비판적인 집단은 이론적으로 코어유틸리티 개발자들이 리눅스 커뮤니티에 귀를 기울이도록 설득하기에 충분해야 합니다.

[해결책] 2가지 방법 중 편한 것을 이용

1) 로그인 유저의 .bashrc파일에 아래 내용을 추가

export QUOTING_STYLE=literal

[참고] 전체 유저에 적용하고 싶다면 /etc/profile 파일 최하단에 추가하면 된다.

2) ls -N 명령어를 alias 설정

alias ls="ls -N"    ( -N, --literal print entry names without quoting)

위 내용을 적용을 희망하는 계정 내  .bashrc 파일에 추가한다.

원문 : http://www.openssh.com/legacy.html

If the client and server are unable to agree on a mutual set of parameters then the connection will fail. OpenSSH (7.0 and greater) will produce an error message like this:

Unable to negotiate with legacyhost: no matching key exchange method found. Their offer: diffie-hellman-group1-sha1

For the case of the above error message, OpenSSH can be configured to enable the 

diffie-hellman-group1-sha1

 key exchange algorithm (or any other that is disabled by default) using the 

KexAlgorithms

 option - either on the command-line:

ssh -oKexAlgorithms=+diffie-hellman-group1-sha1 user@legacyhost

or in the ~/.ssh/config file:

Host somehost.example.org 
KexAlgorithms +diffie-hellman-group1-sha1

OpenSSH 7.0 이상에서는 해당 옵션이 기본으로 enable 되어 있지 않기 때문에옵션을 넣어줘야 한다.항상 넣기 귀찮으니 config를 만들어서 넣고 쓰도록 하자.config파일이 없으면 그냥 생성하면 적용 됨.

OpenSSH 버전확인 명령어 : ssh -V

출처: https://bluelimn.tistory.com/entry/ssh사용-시-diffiehellmangroup1sha1-관련 [ANMIAN:티스토리]