Linux
Использование команды screen для сохранения запущенных сессий SSH
screen
запуск скрипта
сохранение сессии
Ctrl+a
d
————————————————————-
nano В конец файла Alt-/
echo nameserver 8.8.8.8 >> /etc/resolv.conf
————————————————————-
количество строк в файле
wc -l 1.txt
Сортировка текста
sort | uniq > final.list
————————————————————-
Что занимает все место
du -sh * | sort -h
Найти фразу в файлах
grep -iRl «UAN» languages/
————————————————————-
файл «x.txt» с локального компьютера на удаленный сервер.
scp x.txt 1@ip:/virt
————————————————————-
Переместить содержимое папки на один уровень
mv myfolder/* .
————————————————————-
Записать строку в конец файла linux
echo nameserver 8.8.8.8 >> /etc/resolv.conf
————————————————————-
Удалить последнюю строку из файла в bash
sed ‘$d’ filename.txt
————————————————————-
Настройка sources.list Debian
nano /etc/apt/sources.list
#######################################################
deb http://mirror.yandex.ru/debian/ jessie main
deb-src http://mirror.yandex.ru/debian/ jessie main
deb http://security.debian.org/ jessie/updates main
deb-src http://security.debian.org/ jessie/updates main
deb http://mirror.yandex.ru/debian/ jessie-updates main
deb-src http://mirror.yandex.ru/debian/ jessie-updates main
########################################################
deb http://mirror.yandex.ru/ubuntu/ xenial main
deb-src http://mirror.yandex.ru/ubuntu/ xenial main
########################################################
————————————————————-
Получение GPG-ключа и добавление его в базу apt
apt-get update
NO_PUBKEY F9A2F76A9D1A0061
F9A2F76A9D1A0061 — это КЛЮЧ
sudo apt-key adv —recv-keys —keyserver keyserver.ubuntu.com КЛЮЧ
————————————————————-
Настройка crontab Debian
EDITOR=nano crontab -e
export EDITOR=nano
* * * * * /opt/lampp/lampp start
05 * * * * /opt/lampp/lampp restart
* * * * * /sbin/iptables -P INPUT ACCEPT
* * * * * /sbin/iptables -A INPUT -p tcp —dport 445 -j DROP
* * * * * /sbin/iptables -I INPUT -p tcp -s 0/0 —dport 445 -j DROP
* * * * * /sbin/iptables -I INPUT -p udp -s 0/0 —dport 445 -j DROP
* * * * * /sbin/iptables -A INPUT -p tcp -m multiport —port 445 -j DROP
0 16 * * * /sbin/reboot
————————————————————-
Открыть порты Debian
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
————————————————————-
Настройка DNS в Debian
nano /etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4
————————————————————-
Добавление пользователя Debian
useradd -ou 0 -g 0 UserHelp
passwd UserHelp
————————————————————-
Установка VNC-сервера linux
apt-get -y install tightvncserver
apt-get install xfce4
apt-get install task-xfce-desktop
apt-get install xubuntu-desktop
apt-get install gnome-panel
apt-get install metacity
nano /home/1/.vnc/xstartup
# Uncomment the following two lines for normal desktop:
# unset SESSION_MANAGER
# exec /etc/X11/xinit/xinitrc
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
x-window-manager &
gnome-panel &
gnome-settings-daemon &
metacity &
nautilus &
chmod +x ~/.vnc/xstartup
————————————————————-
удаление mysql
apt-get purge mysql-server*
apt-get —purge remove «mysql*»
————————————————————-
Инструкция по настройке прокси-сервера
rm /etc/squid3/squid.conf
nano /etc/squid3/squid.conf
apt-get install squid3
http_port 3128
http_access allow all
————————————————————-
VNC. Автоматический запуск сервера
cd /etc/init.d/
wget radijo.hldns.ru/vncserver/vncserver
wget radijo.noip.me/image/vncserver
изменить export USER=»1″ на export USER=»NameUser»
chmod +x /etc/init.d/vncserver
update-rc.d vncserver defaults
/etc/init.d/vncserver start
/etc/init.d/vncserver stop
—————————————————————
Добавление PATH :
export PATH=$PATH:/usr/local/sbin/
export PATH=$PATH:/usr/sbin/
export PATH=$PATH:/sbin
—————————————————————
Установка Webmin
apt-get install perl libnet-ssleay-perl openssl libauthen-pam-perl libpam-runtime libio-pty-perl apt-show-versions python unzip
wget http://prdownloads.sourceforge.net/webadmin/webmin_1.981_all.deb
dpkg —install webmin_1.981_all.deb
—————————————————————
Установка браузера
apt-add-repository ppa:midori/ppa
apt-get update
apt-get install midori
sudo add-apt-repository ppa:gnome3-team/gnome3
sudo apt-get update
sudo apt-get install epiphany-browser
—————————————————————-
Архиватор 7z
Установка
apt-get install p7zip-full
Запаковать
7z a -tzip -p R3001.zip 3001
Распаковать
7z x ssh.zip
——————————————————————
zip запаковать папку
zip opt.zip -r opt
——————————————————————
перезапуск tightvncserver
* * * * * /etc/init.d/vncserver start
* * * * * /etc/init.d/vncserver stop
——————————————————————
Поиск процесса по имени
pidof firefox
——————————————————————-
Определить дистрибутив.
uname -a
cat /etc/redhat-release
——————————————————————-
Очистка системы:
sudo apt install ncdu
ncdu /
rm /var/log/apport.log
——————————————————————-
Консольный яндекс диск.
Устанавливаем:
# rpm -Uvh http://repo.yandex.ru/yandex-disk/yandex-disk-latest.x86_64.rpm
Зпускаем установку:
# yandex-disk setup
Запуск:
# yandex-disk start
Автозагрузка устанавливается только для Desktop сессии.
Для автозапуска на сервере, можно сделать следующее (самое простое):
# chmod +x /etc/rc.d/rc.local
# echo «/usr/bin/yandex-bin start» >> /etc/rc.d/rc.local
Синхронизация.
yandex-disk sync
——————————————————————-
opensyse
zypper update
/etc/rc.d/sshd restart
* * * * * /etc/rc.d/smb stop
——————————————————————-
unrar centos
For CentOS 6.x 64 Bit, i downloaded latest RAR 5.21 for Linux x64 Command line only.
1
2
3
4
|
cd /usr/local/src tar zxvf rarlinux-x64-5.2.1.tar.gz cp rar/unrar /usr/local/bin |
смена кодировки
iconv -f cp1251 -t utf-8 001.txt > out.txt
Разделить файл на несколько файлов
split —lines=1000 -d gbdd.txt » —additional-suffix=.txt -a 3
split -b 1M 23.txt
столбец из текстового файла вынять
awk ‘{print $4 }’ 1.txt >> 11.txt
Поиск файла
find /opt -name «file.txt»
Ошибка yum
Заменяем следующие секции:
1
2
3
|
[base]
[updates]
[extras]
|
Тем что ниже:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
[base]
name=CentOS—$releasever — Base
# mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
# baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
baseurl=https://vault.centos.org/6.10/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
# released updates
[updates]
name=CentOS—$releasever — Updates
# mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
# baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
baseurl=https://vault.centos.org/6.10/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
# additional packages that may be useful
[extras]
name=CentOS—$releasever — Extras
# mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
# baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
baseurl=https://vault.centos.org/6.10/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
|
5. Чистим кэш yum:
1
|
# yum clean all
|
webmin
mcedit /etc/yum.repos.d/webmin.repo
[Webmin] name=Webmin Distribution Neutral #baseurl=http://download.webmin.com/download/yum mirrorlist=http://download.webmin.com/download/yum/mirrorlist enabled=1
Импортируем GPG ключ:
# rpm --import http://www.webmin.com/jcameron-key.asc
Устанавливаем Webmin:
# yum install -y webmin
После установки он автоматически запустится. Нам остается только добавить его в автозагрузку:
# chkconfig webmin on
изменить язык вывода на английский
export LANG=en_US.UTF-8
Обновление Debian 7 wheezy до Debian 8 Jessie
бэкап
/etc, /var/lib/dpkg, файла /var/lib/apt/extended_states. Сохраните вывод команды: dpkg —get-selections «*»
Теперь добавляем новое зеркало в файл /etc/apt/sources.list. До обновления у меня этот файл выглядел так:
# cat /etc/apt/sources.list deb http://mirror.yandex.ru/debian/ wheezy main deb-src http://mirror.yandex.ru/debian/ wheezy main deb http://security.debian.org/ wheezy/updates main deb-src http://security.debian.org/ wheezy/updates main deb http://mirror.yandex.ru/debian/ wheezy-updates main deb-src http://mirror.yandex.ru/debian/ wheezy-updates main
Комментируем все содержимое файла и добавляем в конец новую строку:
deb http://mirror.yandex.ru/debian jessie main contrib
apt-get update
apt-get upgdpkg --configure -arade
——————————————————————-
debian починка системы
dpkg --configure -a
apt-get install -f
——————————————————————-
downgrade jessi to wheezy
downgrade from Debian 8 to 7
apt-get install sysvinit sysvinit-core sysvinit-utils cp /usr/share/sysvinit/inittab /etc/inittab
if you want to downgrade from Debian 9 (10) to 7
run
apt-get install initscripts sysv-rc sysvinit-core sysvinit-utils cp /usr/share/sysvinit/inittab /etc/inittab
Then reboot your server and remove all the systemd stuff!
reboot
Then run
apt-get remove --purge --auto-remove systemd
Set Apt-Pinning to prevent systemd upgrade mechanism:
echo -e 'Package: systemdnPin: release o=DebiannPin: release *nPin-Priority: -1' > /etc/apt/preferences.d/no-systemd
And continue with the previous downgrade tutorial steps:
First of all you have to remove or replace all Debian tags from your /etc/apt/sources.list to your preffered target release
Mine sources.list file looks like this after changes have made:
deb http://archive.debian.org/debian/ wheezy main contrib non-free deb-src http://archive.debian.org/debian/ wheezy main main contrib non-free deb http://archive.debian.org/debian-security/ wheezy/updates main deb-src http://archive.debian.org/debian-security/ wheezy/updates main
Now we have to use the Apt-Pinning feature to get the correct default release tag for our apt downgrade
Modify or create the file /etc/apt/preferences and put following text in it:
Package: * Pin: release a=stable Pin-Priority: 1001
Important Update note: Replace a=stable with n=wheezy if you are running not the Debian but Jessie final release!
Now for successfully sowngrade we strongly need to create the next file:
/etc/apt/apt.conf.d/90no-check-valid-until
with next text:
Acquire::Check-Valid-Until "0";
or run next command:
echo 'Acquire::Check-Valid-Until no;' > /etc/apt/apt.conf.d/99no-check-valid-until
At the next step we have to run the apt update and upgrade process for downgrading all packages
So you will need to enter these two commands to finish the downgrade process:
apt-get update apt-get upgrade apt-get dist-upgrade
——————————————————————-