Unix vs Linux
- Unix developed in mid-1970 for multi-user, multi-tasking
- Mostly used by SUN and their operating system is Solaris, HP-UX, AIX
- Supports fewer file systems
- Linux in 1991 by Linus Torvalds
- Linux is mostly free
- Open source
- Used mostly by Developer communities, or companies(REDhad, Centos, Debian and many)
- Can be installed on variety of computer hardware, mobiles, tablets, video games, super computers, main frames
- Can be installed on any hardware that is running by Intel & AMD processor
Oracle Virtual Box
- Free and Open source Hypervisor for x86 computers developed by Oracle
Different Linux distributions
- 200+ OS derived from linux like.. Redhat, Ubuntu, Fedora, suse, Debian, Cent os,
- Client
- Windows
- Cygwin
- mac/Linux client
- ssh -V
- Client Server architechture
- ssh client on client system & ssh daemon on Server
- commands
- (sudo) yum -y install nano
- nano /etc/ssh/sshd_config
- edit line #PermitRootLogin yes to no
- systemctl restart sshd
- Navigation commands
- ~ short cut for home directory
- write file
- echo > a.txt
- touch b.txt to create empty file
- running as admin
- sudo <command> run single command as administrator
- sudo su to become administrator
- Install new package
- yum install java yum is package manager for Centos systems
- java -version
- Bash & Shell
- Shell is a processor to process what ever we type in terminal(bash, ksh, fish..)
- Bash is a default processor
- Bash script
- #!/bin/bash -> so say use bash shell
for i in 1 2 3 4 5; do
echo "Hello $i";
sleep 2;
done; - bash <script name>
- Background process
- & at the end of command
- stopping background process
- ps aux
- kill -9 <pid>
- start HTTP server
- sudo python -m SimpleHTTPServer 80
- Environment Variables
- env to list all env variables
- echo $PATH
- export - adds new environment variable
- export abc="asdfasdf"
- Strings
- " -> interpolating variables
- ' -> preserving strings exactly
- ` -> interpolating command output
- echo "today is `date`"
- Linux commands demistified
- linux commands are executables
- which <command> gives the location
SSH Fundamentals
- Interactive ssh
- ssh user@[hostname/ipaddress]
- long lived processes
- start process and keep it running after terminating ssh session
- nohup <command>
- It separates process from terminatl
- non-interactive ssh
- run multiple commands at a time
- ssh user@[hostname/ipaddress] <command>
Creating Server Alias
- ~/.ssh/config add following
Host [server_nickname]
hostname [Server IP address]
user [username]
How SSH works
- SSH daemon listens at port 22
- ECDSA is unique signature of server which can't be tampered. ESDSA is sent to client
- Encrypted communication channel gets created between both parties
- Client sends authentication details on encrypted channel
- Server verified
- communication channel gets established.
Uploading files(SCP)- uses ssh internally
- upload
- scp [local source path] user@[hostname/ipaddress]:[server_target_path]
- download
- scp user@[hostname/ipaddress]:[server_source_path] [local target path]
SFTP - ssh file transfer protocol
- download cyberduck
SSH Key Authentication
- Avoid typing password
- More secure
- Problem with passwd authentication
- Secret information is sent over communication channel which can compromise security
- Process
- Generate public and private key (ssh key pair)
- Upload public key on server
- Tell client to use SSH authentication
- Private & Public key
- AssyPublic key can be distributed
- Private key to be kept confidential
- Data encrypted with public key can only be decrypted with private key
- Private key cannot be figured out from public key
- Public key can be figured/derived out from Private key
- Generate ssh keys
- ssh-keygen -t rsa -b 4086 -C "just comments"
- Connect to server ~/.ssh/authorized_keys file
- copy content of public key to authorized_keys on a new line
- Test ssh keys
- ssh -i [privatekey] [user]@[server]
Amazon EC2
- sudo su - to become a root user
- Dir structure
- / ->ROOT directory similar to C:\ in windows
- /root -> home directory for root user- similar to C:\Document and Setting\Administrator
- /home -> home directory for other users- similar to C:\Document and Setting\username
- /usr -> softwares are installed- similar to c:\program files
- /bin -> commands used by all users
- /sbin -> commands used by super user(root)
- /var -> container variable data like logs, mails..
- Basic commands
- User Management
- Super or root user -> most powerful & admin user
- /root is home directory with shell /bin/bash
- Sytem user ->Created by applications or softwares
- /var/ftp is home directory with shell /sbin/no login
- Normal user ->
- /home/<user> is home directory with shell /bin/bash
- user creation
- useradd <option> <name>
- UID & GID will be assigned to user
- Software Management
- yum for REDHAT
- yum install <package>
- yum remove
- yum update
- yum info
- yum list
- yum install wget
- Networking
- hostname ->servername
- init 6 or reboot -> restart system
- ping -> to check if target is available or not
- wget -> download files/packages
- ifconfig -> to get ipaddress of your system
- telnet ->to check if a particular port is used or not
- curl ->access appln as from browser
- port numbers
- ftp - 21
- ssh -22
- telnet - 23
- smtp - 25
- dns - 53
- http - 80
- https - 443
- ports usage
- netstat -tulpn
- Services(systemctl)
- Service
- Controls starting and stopping of services
- service <name> <status | start | stop | reload | restart>
- yum install httpd -> command to install http
- service httpd status
- service httpd start
- telnet localhost 80
- curl localhost
- chkconfig
- Check availability of service
- chkconfig --list
- chkconfig <service> <on | off> -> to make service available/unavailable after restart(boot time)
SSH(Secure shell)
- Method for secure remote login from one computer to another.
- Provides alternative options for authentication
- Protects communications security and integrity with strong encryption
- port - 22
- Daemon - sshd
- conf file - /etc/ssh/sshd_config
- HTTP
- port - 80
- Daemon - httpd
- conf file - /etc/httpd/conf/httpd_config
- default file - /var/www/html
- ps -ef -> list of processes which are running in system
- kill -9 -> kill a process or service
- jobs -> gives list of jobs getting executed
- fg & %<job id> -> run process in foreground
- bg -> run in background
- top -> list top 20 process which are consuming more cpu
Archiving
- gzip
- Create compressed file
- gzip <file> -> file.gz gets created
- gunzip
- gunzip <file.gz>
- tar
- extract tar file
- works on directories
- tar -cvf <directory> dir1.tar directory1
- tar -xvf dir1.tar -> tar is a file
- gzip dir1.tar ->dir1.gz
- tar -xvzf dir1.gz to extrat tar & directories -> does 2 steps
CronTab
- daemon called crond
- job scheduling
- crontab -l
- List crons
- crontab -e
- Min Hr Day_Of_Month Month Day_of_week <command>
- Execute job at 8.30 in mornring
- 30 8 * * *
- Execute job at 2 pm every saturday
- 0 14 * * 6
- Execute job at 12am on Jul1st
- 00 00 1 6 *
- Execute job at 3.30pm every month 25th
- 30 15 25 * *
Link files
- Softlink
- shortcut file
- ln -s <source file> <dest file>
- used to create short cut of shell script at /usr/local/bin/hello
- Harklink
- Backup file
- ln <source file> <dest file>
- Mobaxterm
- winscp
Copy from LINUX to LINUX server
- scp
No comments:
Post a Comment