Difference between revisions of "Dev:Linux"

From C3LearningLabs
(Net)
(Net)
Line 164: Line 164:
 
Used ports : <code>netstat -tln</code><br>
 
Used ports : <code>netstat -tln</code><br>
 
Get Network Interface in computer : <code>ifconfig -a</code><br>
 
Get Network Interface in computer : <code>ifconfig -a</code><br>
 +
 +
*nmap
 +
:<code>sudo apt install nmap</code>
 +
:<code>nmap localhost</code>
 +
:<code>nmap 192.168.122.31</code>
 +
:<code>nmap 192.168.122.31 -p8000-9000</code>
 +
 +
*wget
 +
:<code>wget 192.168.122.31:8080</code>
 +
  
 
IPNr : 192.168.1.241
 
IPNr : 192.168.1.241

Revision as of 12:30, 3 December 2019


Shell Commands

Info

Processor: lscpu
Linux info: uname -a
Linux info: cat /etc/upstream-release/lsb-release
Linux info: lsb_release -a

File

move : mv
Create link : ln -s target linkname

Delete all files in Download Folder
sudo rm -rfv /home/rego/Downloads/

USB
cd /Volumes/WORK-REGO
cd /Volumes/WORK-REGO/Work/RISE
cd /Volumes/WORK-REGO/Work/RISE/SvärmarAvDrönare


Count files
One Folder: ls | wc -l
Recursively: find . -type f | wc -l

Zip
Create: gzip file.xxx
Unzip: gzip -d file.gz

tar
Make: tar -pczf name_of_your_archive.tar.gz /path/to/directory

Dir
make dir : mkdir dir
Delete Dir : rm -rf dir

Find file
find /home/username/ -name "*.pbtxt"
find / -name "*.pbtxt"
find / -name "php.ini" 2> /dev/null

Rename multiple files - mmv
Linux: sudo apt-get install mmv
Mac: brew install mmv

mmv <FROM>\* <TO>\#1

Example:

$ ls
a1.txt a2.txt a3.txt
mmv a\* b\#1
ls
b1.txt b2.txt b3.txt

Example:
cd /Users/regogranlund/dev/C3Systems/C3Systems/resources/C3Fire/SessionDef/P4FWRU-1 mmv P8F3WR3U2\* P4FWRU\#1

Replace String in multiple files

sudo find . -type f -name "*.txt" -print0 | xargs -0 sed -i "" -e 's/[FROM]/[TO]/g'

Example:
cd /Users/regogranlund/dev/C3Systems/C3Systems/resources/C3Fire/SessionDef/P4FWRU-1

sudo find . -type f -name "*.con*" -print0 | xargs -0 sed -i "" -e 's/P8F3WR3U2/P4FWRU/g'


File access

Protection : chmod 555 <filnamn> : -r-xr-xr-x
Protection : chmod 777 <filnamn> : -rwxrwxrwx
Protection : chmod 775 <filnamn> : -rwxrwxr-x

Protection, for all in tree : chmod -R 775 *

sudo chmod -R 777 /data

Owner, for all in tree : chown -R rego *
Owner, for all in tree : chown -R rego:wwwadm *
Group, for all in tree : chgrp -R adm *

sudo chown -R granlund /data

Disk

remove dir: sudo rm -rf

Se diskar
lsblk
sudo sfdisk -l
sudo fdisk -l
sudo parted -l

Se Filsystem : df -h

smartmontools

https://help.ubuntu.com/community/Smartmontools

sudo apt-get install smartmontools

sudo smartctl -i /dev/sdb

How long a test will take: sudo smartctl -c /dev/sdb

Get Info: sudo smartctl --all /dev/sdb

Mount disk

Get Share names on disk: smbclient -L //192.168.1.200/

Temorary mount samba disk

sudo mount -t cifs -o domain=domain_name,user=user_name,password=password,vers=2.1 //myServerIpAdress/sharename /mnt/myFolder/

Example

sudo mkdir /mnt/cydonia
sudo mount -t cifs -o domain=MUMINDALEN,user=granlund,password=xxxxxxxxx,vers=1.0 //192.168.1.200/Cydonia /mnt/cydonia


If error, view error message tail /var/log/syslog

Unmount sudo umount /mnt/cydonia

Mount on Boot

edit /etc/fstab Add the following information

//<IP address of NAS box 192.168.x.y>/<shared folder> /<mount point> cifs user=<user on NAS>,pass=<passwd on NAS> 0 0

If you never set any users up on the NAS then it would look like this

//<IP address of NAS box 192.168.x.y>/<shared folder> /<mount point> cifs guest,_netdev,uid=<your user name on Linux box> 0 0


Example
edit /etc/fstab: sudo pico /etc/fstab

Add the following text
//192.168.1.200/Cydonia /mnt/cydonia cifs guest,_netdev,uid=rego 0 0

To activate: sudo mount -a

Net

Edit Netplan
cd /etc/netplan
sudo cp /etc/netplan/50-cloud-init.yaml /etc/netplan/50-cloud-init.yaml.bak
sudo nano /etc/netplan/50-cloud-init.yaml
sudo netplan try or sudo netplan apply

Show ip : ip addr show
Used ports : netstat -tln
Get Network Interface in computer : ifconfig -a

  • nmap
sudo apt install nmap
nmap localhost
nmap 192.168.122.31
nmap 192.168.122.31 -p8000-9000
  • wget
wget 192.168.122.31:8080


IPNr : 192.168.1.241

Get IP Nr: ifconfig

IP Config File : /etc/network/interfaces
sudo cp interfaces /etc/network/


Vilka portar som används netstat -tln

Get Network Interface in computer : ifconfig -a

DNS Info/Config sudo pico /etc/resolv.conf

DNS Info systemd-resolv --status

DNS Static
Static hostnames are locally defined hostname-to-IP mappings located in the file /etc/hosts.
sudo pico /etc/hosts

  • Test connection
localhost:8080

Scan

sudo apt-get install nmap

sudo nmap 192.168.1.* -sP > file1.txt


sudo nmap 192.168.1.0/24 -sP > file1.txt

Startup

sudo reboot

Package

Repository

https://help.ubuntu.com/community/Repositories/CommandLine

Repositories or software channels are stored in the file

/etc/apt/sources.list

and in any file with the suffix .list under the directory

/etc/apt/sources.list.d/


View main Repository

more /etc/apt/sources.list

Edit sudo pico /etc/apt/sources.list

Test if package possible to find

apt-cache madison docker-ce

Users

Root
root access : sudo
Activate root acount : sudo passwd root
Login to root : su root
Set Password
sudo passwd rego
Add user to group 
useradd -G {group-name} username
sudo adduser --system --home /etc/minecraft minecraft
sudo addgroup --system minecraft
sudo adduser minecraft minecraft
List all users
cut -d: -f1 /etc/passwdlo
cut -d ":" -f 1 /etc/passwd
compgen -u
List members of a group
getent group www-data
List what groups a user is member of
groups rego
Create User home directory
Create User home directory, Not just a folder, the default home directory with all it's folders and hidden files, etc
For this to work, folder /home/username must NOT exist.
sudo mkhomedir_helper regogr
Set Bash shell
sudo usermod -s /bin/bash regogr

Groups

List all groups the currently logged in user belongs to

groups

List all groups the specified user belongs to

id regogr

List all groups the currently logged in user belongs to

groups

Scrips

Getting User Input Via Keyboard :

 read -p "Enter your name : " name
 echo "Hi, $name. Let us be friends!"


Packages

/etc/apt/sources.list
ls /etc/apt/sources.list.d

sudo rm -rf /var/lib/apt/lists/*
sudo apt-get update
sudo apt-get clean

Mount disk

sudo mkdir /TempDisk
sudo mount /dev/sdc /TempDisk

sudo umount /TempDisk

sudo parted /dev/sdc
sudo gpart /dev/sdc

Disk Partionerare : sudo cfdisk


Disk space : df -k
Catalog Space : du -k -s *



Delete a partition

https://www.cyberciti.biz/faq/linux-how-to-delete-a-partition-with-fdisk-command/

sudo fdisk /dev/sdb
p d 1 d 2 d 3 p w

sudo reboot


Rescue Disk

https://help.ubuntu.com/community/DataRecovery http://iso.linuxquestions.org/ubuntu-rescue-remix/ https://www.gcsdstaff.org/roodhouse/?p=1933

sudo btrfs filesystem show /dev/sdc
sudo mount -o recovery /dev/sdc /mnt


Fix! Read-only file system

https://askubuntu.com/questions/197459/how-to-fix-sudo-unable-to-open-read-only-file-system

sudo fsck.ext4 -f /dev/sda1

Repair a broken Ext4 Superblock in Ubuntu

https://help.ubuntu.com/community/Boot-Repairhttps://linuxexpresso.wordpress.com/2010/03/31/repair-a-broken-ext4-superblock-in-ubuntu/

sudo fsck.ext4 -v /dev/sda1

sudo mke2fs -n /dev/sda1
Nooooo


   e2fsck -b 8193 <device>
or
   e2fsck -b 32768 <device>

See! https://askubuntu.com/questions/885062/root-file-system-requires-manual-fsck/885085

fsck -fy /dev/sda1


sudo mount /dev/sdc /TempDisk


Linux folder usage

/ is the root. It is the highest level of the filesystem. At the very beginning of the filesystem setting up, this directory — as some other sub directories — is purely virtual — residing in RAM —, then the partition that contains the final root of the filesystem is mounted there read-only. Thus the kernel is able to find the tools necessary to the initialization of disks and the mounting of the other partitions. After this job is done, the partition is remounted read write.
/home, it the place where the files of the users will be placed. Generally, but it is not mandatory, a separate partition is mounted there.
/etc is the place for installed application configuration files e.g. /etc/fstab, /etc/hosts, etc.
/lib is the place for shared libraries and the kernel modules.
/media is a mounting point for removable devices such as CDs, DVDs, USB stick or drives, etc.
/bin is a place for essential command binaries such as cat, ls, mount…
/boot is a place for static files of the boot loader.
/dev is for the device files.
/mnt is a place where to mount filesystems temporarily.
/opt is for additional programs.
/run is for data related to running processes.
/sbin is for essential commands.
/srv is for the data of service supported by the system e.g. the file of a web server. l
/tmp is for temporary files
/usr is a secondary hierarchy.
/var is for variable data
/root is for the files belonging to the super user (root)

SSH

http://www.hypexr.org/linux_scp_help.php

sudo scp -p 23122 regogr@10.112.46.3:/home/regogr/cvat/docker-compose.yml /home/rego

https://unix.stackexchange.com/questions/106480/how-to-copy-files-from-one-machine-to-another-using-ssh

Mint UI

LAN Network

To see all files in Network

  • Open Files
  • Open Windows Network
  • Connect as Anonymous


Applications

All .desktop files are stored in: /usr/share/applications

Chrome

  • Install
    cd /home/rego/Downloads
    sudo dpkg -i google-chrome-stable_current_amd64.deb
  • Delete all files in Download folder
    sudo rm -rfv /home/rego/Downloads/

LibreOffice

  • Download
    www.libreoffice.org/download/
    Select Linux_x86_64.deb
  • Unzip
    cd /home/rego/Downloads
    tar xvf LibreOffice_6.2.5_Linux_x86-64_deb.tar.gz
  • Install
    cd /home/rego/Downloads/LibreOffice_6.2.5.2_Linux_x86-64_deb/DEBS
    sudo dpkg -i *.deb
  • Delete all files in Download folder
    sudo rm -rfv /home/rego/Downloads/

FreeFileSync

  • Install
    mkdir /home/rego/Apps
    mv /home/rego/Downloads/FreeFileSync_10.14_Linux.tar.gz /home/rego/Apps/
    cd /home/rego/Apps
    tar xvf /home/rego/Apps/FreeFileSync_10.14_Linux.tar.gz
    rm /home/rego/Apps/FreeFileSync_10.14_Linux.tar.gz


  • Edit the desctop start file, /home/rego/Apps/FreeFileSync/FreeFileSync.desktop
[Desktop Entry]
Type=Application
Name=FreeFileSync
GenericName=Folder Comparison and Synchronization
GenericName[de_DE]=Ordnervergleich und Synchronisation
Exec=/home/rego/Apps/FreeFileSync/FreeFileSync %F
Icon=/home/rego/Apps/FreeFileSync/Resources/FreeFileSync.png
NoDisplay=false
Terminal=false
Categories=Utility;FileTools;
StartupNotify=true
  • Make the file executable (chmod +x something.desktop)
    chmod 777 /home/rego/Apps/FreeFileSync/FreeFileSync
  • Copy to application folder
    sudo cp /home/rego/Apps/FreeFileSync/FreeFileSync /usr/share/applications/FreeFileSync
  • Make the file executable (chmod +x something.desktop)
    sudo chmod 777 /usr/share/applications/FreeFileSync
  • Make link to desktop
    ln -s /usr/share/applications/FreeFileSync /home/rego/Desktop/FreeFileSync
  • Make the file executable (chmod +x something.desktop)
    sudo chmod 777 /home/rego/Desktop/FreeFileSync
  • Run
    /home/rego/Apps/FreeFileSync/FreeFileSync
    /usr/share/applications/FreeFileSync
    /home/rego/Desktop/FreeFileSync

Ubuntu UI

GNOME Tweak Tool

  • Install gnome-tweak-tool
    sudo apt install gnome-tweak-tool

LAN Network

To see all files in Network

  • Open Files
  • Open + Other Locations
  • Open Windows Network
  • Connect as Anonymous

Program Install

Applications

All .desktop files are stored in: /usr/share/applications


FreeFileSync

  • Install libgtk2.0-0:i386
    sudo apt install libgtk2.0-0:i386
  • Unzip
    /home/rego/Apps
  • Edit the desctop start file, /home/rego/Apps/FreeFileSync/FreeFileSync.desktop
[Desktop Entry]
Type=Application
Name=FreeFileSync
GenericName=Folder Comparison and Synchronization
GenericName[de_DE]=Ordnervergleich und Synchronisation
Exec=/home/rego/Apps/FreeFileSync/FreeFileSync %F
Icon=/home/rego/Apps/FreeFileSync/Resources/FreeFileSync.png
NoDisplay=false
Terminal=false
Categories=Utility;FileTools;
StartupNotify=true
  • Make the file executable (chmod +x something.desktop)
    chmod 777 /home/rego/Apps/FreeFileSync/FreeFileSync
  • Copy to application folder
    sudo cp /home/rego/Apps/FreeFileSync/FreeFileSync /usr/share/applications/FreeFileSync
  • Make the file executable (chmod +x something.desktop)
    sudo chmod 777 /usr/share/applications/FreeFileSync
  • Make link to desktop
    ln -s /usr/share/applications/FreeFileSync /home/rego/Desktop/FreeFileSync
  • Make the file executable (chmod +x something.desktop)
    sudo chmod 777 /home/rego/Desktop/FreeFileSync
  • Run
    /home/rego/Apps/FreeFileSync/FreeFileSync
    /usr/share/applications/FreeFileSync
    /home/rego/Desktop/FreeFileSync

Apache

/etc/apache2/

/var/www/html/index.html



SSH

https://help.ubuntu.com/12.04/serverguide/ftp-server.html

Install : sudo apt-get install vsftpd


WinSCP user : rego Port : 22 Protocol : SFTP, Allow SCP Fallback



Fixa MySQL


mysql -u root -p CREATE USER 'rego'@'localhost' IDENTIFIED BY 'password'; GRANT ALL PRIVILEGES ON * . * TO 'rego'@'localhost'; GRANT ALL PRIVILEGES ON * . * TO 'www-data'@'localhost'; create database photo; grant all privileges on photo.* to rego@localhost; grant all privileges on photo.* to root@localhost;



Fix PHP


sudo apt-get install php5-gd



Set up user


New User : rego


Plugins


elFinder downloadList


set Maximum image size


Edit php.ini

memory_limit = 128M post_max_size = 1G file_uploads = On upload_max_filesize = 1G max_file_uploads = 20

cd /home/rego/files sudo cp php.ini /etc/php5/apache2/

TightVNC

funkar inte med ssh tunneln

port : 5901

Start : /usr/bin/tightvncserver Start : sudo service vncserver start

vncserver -kill :1


Install



sudo apt-get update sudo apt-get install tightvncserver

set pasword : vncserver for viewer I used : granlund

Config


vncserver -kill :1 mv ~/.vnc/xstartup ~/.vnc/xstartup.bak

Edit config file

nano ~/.vnc/xstartup

läggtill raderna

  1. !/bin/bash

xrdb $HOME/.Xresources startxfce4 &

exit ^X


sudo chmod +x ~/.vnc/xstartup

VNC Service File


sudo nano /etc/init.d/vncserver

  1. !/bin/bash

PATH="$PATH:/usr/bin/" export USER="rego" DISPLAY="1" DEPTH="16" GEOMETRY="1600x900" OPTIONS="-depth ${DEPTH} -geometry ${GEOMETRY} :${DISPLAY} -localhost" . /lib/lsb/init-functions

case "$1" in start) log_action_begin_msg "Starting vncserver for user '${USER}' on localhost:${DISPLAY}" su ${USER} -c "/usr/bin/vncserver ${OPTIONS}"

stop) log_action_begin_msg "Stopping vncserver for user '${USER}' on localhost:${DISPLAY}" su ${USER} -c "/usr/bin/vncserver -kill :${DISPLAY}"

restart) $0 stop $0 start

esac exit 0


exit ^X


sudo chmod +x /etc/init.d/vncserver


sudo service vncserver start

sudo update-rc.d vncserver defaults


Fick det inta att funka, installerade om

sudo apt-get remove tightvncserver sudo apt-get install tightvncserver

/usr/bin/tightvncserver

startade då man använde configdata från första instalatioen


Piwigo

http://192.168.1.241/piwigo/


cd /var/www/html/piwigo/ sudo chmod 777 _data

MySQL database Configuration

create DB manually : piwigo

Host : localhost User : root Password : Database name : piwigo Prefix : piwigo_

The webmaster account creation requires:

Username : rego Password : Email address: rego.granlund@gmail.com

copy database.inc.php To /var/www/html/piwigo/local/config/database.inc.php

cd /var/www/html/piwigo sudo chmod 777 upload sudo chmod 777 plugins


Add Plugins


Batch Downloader BBCode Bar Embedded Videos GuestBook Header Manager jplayer rotateImage Smilies Support user delete photo User Tags Whois Online

Users


hillevi.granlund rego.granlund rego.granlund@gmail.com edvin.granlund helena.granlund vivi.granlund lena.sundqvist

sam.ekenkrantz sam.ekenkrantz@addici.com lena.ekenkrantz

carina.kylner carina.kylner@telia.com

stefan.albinsson stefan.albinsson@gmail.com

peter.ljungdahl peter@ljungdahl.net ninni.ljungdahl ninni@ljungdahl.net

peter.enderborg mario.dugandzic maria.dugandzic

joe.mendes

bengt-erik.andersson


Midsommar bilder

Hej Snart midsommar!!!

Har satt upp en foto server hemma hos mig. Har lagt upp midsommar bilder på den. Detta var skoj. Jag har satt er till administrator så att ni kan ladda upp bilder till server. Om ni laddar upp bilder så ladda upp den bästa kvaliteten, dvs original bilderna.

Mario, Ladda INTE upp vissa bilder, :-) Mario, Om du vill kan jag installera en PayPal plugin först. :-)

Skriv kommentarer mm.

Har inte lärt mig allt vad man kan göra. Håller på att lära mig.

Har inte lärt mig hur man lägger dit filmer än, men det skall gå om man installerar rätt plugin.

Obs jag kan ha glömt att sätta behörighets nivåerna rätt på alla ställen.

Skall försöka ta backup på det vi skriver.


Surfa till http://88.206.190.33/piwigo/

user: lena.sundqvist password: qwerty

Ses snart Rego


Sätt antal bilder som skall visas på en sida Customise -> Number of photos per page

Sätt password Customise -> Password


MYSQL

Starta : mysql -u root -p mysql -u rego -p photo

  • Set IPNr and Port

FTP /files/my.cnf cd /home/rego/files sudo cp my.cnf /etc/mysql/

  • Restart

sudo /etc/init.d/mysql restart


Create User

CREATE USER 'rego'@'localhost' IDENTIFIED BY 'password'; GRANT ALL PRIVILEGES ON * . * TO 'rego'@'localhost';


Skapa Databas

create database photo; grant all privileges on photo.* to rego@localhost;


mysql -u rego -p'amarokpasswd' photo


phpMyAdmin

sudo apt-get install phpmyadmin

http://192.168.1.241/phpmyadmin

user : root


PHP

Install GD (Graphics support) : sudo apt-get install php5-gd


Samba

FTP /files/my.cnf Config : /etc/samba/smb.conf

cd /home/rego/files sudo cp smb.conf /etc/samba/

  • Create the shared folder and user

sudo mkdir -p /srv/samba/Phobos sudo chown nobody.nogroup /srv/samba/Phobos/


sudo smbpasswd -a rego sudo smbpasswd -a granlund


sudo stop smbd sudo restart smbd sudo restart nmbd