Sunday, April 10, 2016

Linux Admin braindump --Rasbian, Unbuntu


SD Formatter (SD card Association), RasberryPi.org download NOOBS 1G boot menu+Rasbian
[Putty SSH shutdown RasPi] halt -h //wait all LED off, cmd poweroff not work
passwd pi useradd  -p xxxxxx -G adm jimmy groups //list all groups cut -d: -f1 /etc/group
raspi-config //enable SSH change password reboot pm-hibernate 
ifconfig -a iwlist scan hostname -I iwlist wlan0  essid Cap15 //try to get wifi dhclient wlan0 ifconfig wlan0 up/down service ssh start
cd=cd / cal cal-3 cal 7 14 1995 date date --date "30 days ago" "30 days"  free -m top shit-f s %MEM [esc] // sort by mem
lsb-release -a uname -r //system, kernel info distrowatch.com
tty w=who chvt apt-get update/dist-upgrade ssn localhost exit lsscsi lsub lspci lshw //hardware info uptime uname -a which lsscsi //file path
/dev /sys /proc /proc/interrupts //pseudo file system IRQ 0=system timer 75=nic //use cat/ls on pfile watch -n1 head -n 10 interrupts // 1sec realtime interrupts upd hwclock --systohc // copy system time to hardware clock see rtc0 upd gnome-system-monitor //=taskmgr cat /sys/block/sda/size cd /dev/sda cd /proc/14 cat stack  /sys vs /dev meta data

sofware management
/var/lib/rpm /apt  rpm -qa apt list rpm -i/-e 
rpm -vhU https://nmap.org/dist/nmap-7.12-1.x86_64.rpm
rpm -qf $(which nmap)
apt-get install yum

RH/CentOS -- rpm -qpi //query pkg info -qpl //list /etc/repo.d loca.repo [local] baseurl=file:///repo mkdir /repo yum install createrepo createrepo /repo yum install nmap //w/o repo this will not work

debian/ubuntu --- dpkg -i -r -s -L -l dpkg-reconfig apt repository apt-get update ls /var/cache/apt apt-cache search postfix
cat /etc/apt/sources.list //rabian or ubuntu repo url  apt-cache pkgnames postfix //search a pkg to install

shared lib--user module
ldd /bin/ls DLL=.so .ko //shared kernel cat /etc/ld.so.conf //PATH less /etc/ld.so.conf.d/libc.conf ldd $(which useradd) ldconfig ldconfig -p mkdir /testlib cp librt.so.0 export LD_LIBRARY_PATH=/testlib/ ldd /bin/ls  // dependency shows testlib unset LD_...

shared lib--kernel module
lsmod | grep psmouse = grep psmouse /proc/modules // show size dependcy modinfo psmouse modprobe -r psmouse modprobe psmouse //remove add
ls /etc/modprobe.d less blacklist.conf //not loading outdated modules

file management
lsblk ls -l /dev/sda //show brw-rw.. b=block lsblk /dev/sda fdisk -l /dev/sda  gdisk parted /dev/sda print mkfs. XFS ext4 apt-cache pkgnames xfs mkdir -p /data/{d1,d2} // can mount to dir  blkid /dev/sdb1  mount mount -t ext4 -o acl,noexec /dev/sdb1 /mnt unmount /mnt /etc/fstab

Swap file
mkswap swapon --show = free -m /var/swap on RasPi /dev/sda6 gdisk

partprobe /dev/sda6 //avoid reboot to sync new parti cat/proc/partitions ls /dev/sda* mkswap /dev/sda3 swapon /dev/sda3 gdisk /dev/sda6 select p=print parti table n=new parti 3=sda3 8200=linux swap file others like Microsoft reserved
swapoff /dev/sda3 swap on -p 10 /dev/sda3 //priority 10 vi /etc/fstab sw, pri=10 //mount by editing
add a new line /dev/sda3 none swap, pri=10 0 0 //no mount point, 0 dump 0 check on restart
mount -a //read, refresh mount map swapon -a //read swap file swapon -s =show 
dd if=/dev/zero of=/root/swapfile1 count=1000 bs=1024 //init NULL dd=disk imaging copy mkswap /rro/swapfile1 // not mkfs
swap -p 10 /root/swapfile1 swapon -s grep swap /etc/fstab  //now swapfile1 is virtual mem swapfile
du df dd //file and disk usage imaging tune2fs e2fsck dumpfs debugfs //tunable ext2,3,4 check tune2fs -L 'label1' /dev/sda5
df -lhT //local human type du -hs /etc //human size dumpe2fs /dev/sda5 mount
dd if=/dev/sda of=/data/backup/file1 count=1 bs=512 //back up 1st boot rec fdisk -l //show boot rec
tar -cvf /data/backup/etc.tar /etc //backup etc create verbose file
debugfs /dev/sda5 ls ls -d <14>=deleted file stat <14> apt-get install extundelete extundelete --inode 89 /dev/sdb1 //inode=fs data structure extundelete --restore-file dir1/1.confi /dev/sdb1 ~RECOVERED_FILES mount -a cp //need manually copy files

permission
id sudo -i //switch to root user cannot change root passwd su - ask password  exit //logout super user
ugo=usr group other rwx symbolic/octal 7=111=rwx 6=110=rw 4=100=r chmod chown chgrp stat umask
stat f1.txt =ls -l //verbose show octal and sym mkdir -p /data/dir{1,2,3} umask //show defautl 2=0002 umask 0 //now 0000 =>true default for files touch f1.txt =>rw-rw-rw //666 not 664 by umask umask 007=>touch f3.txt show rw-rw-r-- x not set even allowed
umask 007 // 7=rwx, 6=rw 4=r 1=x not allow 0=any can be set
ls -ld . //drwx-rw- current dir perm chmod 777 chmod u=rwx g=rw o=r chmod +rw -rw
chgrp users /dir1 //perm now for users not root 
sticky bit on dir --- /dir1 -rwx /dir1/f1.txt -r-- // readonly still can delete if parent dir rw chmod o+t /dir1 can no longer delete f1.txt ls -ld /dir1 drwxrwxrwxT //t=sticky bit prevent readlonly file deletion for others
hard/soft link --- . is a link current dir ls -a //at least two links . ..   filename inode[meta data] are two links stat->stat file->stat f1.txt ls -ld doc find /usr/share/doc -maxdepth 1 -type d |wc -l // count subdir | head -n 3 
ln f1.txt hl1 //hard link ln -s f1.txt sl1 //soft link  stat f1.txt //show same inode for hard diff for soft ls -li f.txt //show inode
dd if=/dev/zero of=/data/big.txt count=1 bs=1024M //create 1G file for testing

Linux Boot up and Service Control
find . -name "menu.lst" /etc/init grep -i default_run * //case insensitive runlevel 0=halt 1=single user 2=multi no gui/no netw 3=no gui 5=full gui 6=reboot //no 4  init 0 init 2 ubuntu/debia 2=3=5 /etc/init upstart rc-sysinit.conf env DEFAULT_RUN_LEVEL=2
runlevel = who -r //show N 2 N5  telinit 6 telinit 3 halt =into BIOS
boot procedure: pwr self-test =>locate MBR (master boot rec) =>boot loader (kernel/Ram disk) =>kernel/Ram disk =>init Daemon (RunLevel 5 for desktop 3 for server)
grub grub2 menu.lst Grand Unified boot loader shutdown poweroff reboot shutdown -r now shutdown -h 18:27 "donw at 6pm" -h +5"in 5min" shhutdown -c //cancel or Ctrl+c

service status start stop restart netstat -anl ls /etc/init.d /etc/inittab chkconfig --list sshd update-rc.d -f sshd remove update-rc.d sshd defaults



No comments:

Post a Comment