├── .gitignore ├── 0x00-shell_basics ├── 0-current_working_directory ├── 1-listit ├── 10-back ├── 100-lets_move ├── 101-clean_emacs ├── 102-tree ├── 103-commas ├── 11-lists ├── 12-file_type ├── 13-symbolic_link ├── 14-copy_html ├── 2-bring_me_home ├── 3-listfiles ├── 4-listmorefiles ├── 5-listfilesdigitonly ├── 6-firstdirectory ├── 7-movethatfile ├── 8-firstdelete ├── 9-firstdirdeletion ├── README.md └── holberton.mgc ├── 0x01-shell_permissions ├── 0-iam_betty ├── 1-who_am_i ├── 10-mirror_permissions ├── 100-change_owner_and_group ├── 101-symbolic_link_permissions ├── 102-if_only ├── 103-Star_Wars ├── 11-directories_permissions ├── 12-directory_permissions ├── 13-change_group ├── 2-groups ├── 3-new_owner ├── 4-empty ├── 5-execute ├── 6-multiple_permissions ├── 7-everybody ├── 8-James_Bond ├── 9-John_Doe └── README.md ├── 0x02-shell_redirections ├── 0-hello_world ├── 1-confused_smiley ├── 10-no_more_js ├── 100-empty_casks ├── 101-gifs ├── 102-acrostic ├── 103-the_biggest_fan ├── 11-directories ├── 12-newest_files ├── 13-unique ├── 14-findthatword ├── 15-countthatword ├── 16-whatsnext ├── 17-hidethisword ├── 18-letteronly ├── 19-AZ ├── 2-hellofile ├── 20-hiago ├── 21-reverse ├── 22-users_and_homes ├── 3-twofiles ├── 4-lastlines ├── 5-firstlines ├── 6-third_line ├── 7-file ├── 8-cwd_state ├── 9-duplicate_last_line ├── README.md └── list ├── 0x03-shell_variables_expansions ├── 0-alias ├── 1-hello_you ├── 10-love_exponent_breath ├── 100-decimal_to_hexadecimal ├── 101-rot13 ├── 102-odd ├── 103-water_and_stir ├── 11-binary_to_decimal ├── 12-combinations ├── 13-print_float ├── 2-path ├── 3-paths ├── 4-global_variables ├── 5-local_variables ├── 6-create_local_variable ├── 7-create_global_variable ├── 8-true_knowledge ├── 9-divide_and_rule └── README.md ├── 0x04-loops_conditions_and_parsing ├── 0-RSA_public_key.pub ├── 1-for_best_school ├── 10-fizzbuzz ├── 100-read_and_cut ├── 101-tell_the_story_of_passwd ├── 102-lets_parse_apache_logs ├── 103-dig_the-data ├── 2-while_best_school ├── 3-until_best_school ├── 4-if_9_say_hi ├── 5-4_bad_luck_8_is_your_chance ├── 6-superstitious_numbers ├── 7-clock ├── 8-for_ls ├── 9-to_file_or_not_to_file ├── README.md └── apache-access.log ├── 0x05-processes_and_signals ├── 0-what-is-my-pid ├── 1-list_your_processes ├── 100-process_and_pid_file ├── 101-manage_my_process ├── 102-zombie.c ├── 2-show_your_bash_pid ├── 3-show_your_bash_pid_made_easy ├── 4-to_infinity_and_beyond ├── 5-dont_stop_me_now ├── 6-stop_me_if_you_can ├── 67-stop_me_if_you_can ├── 7-highlander ├── 8-beheaded_process ├── README.md └── manage_my_process ├── 0x06-regular_expressions ├── 0-simply_match_school.rb ├── 1-repetition_token_0.rb ├── 100-textme.rb ├── 2-repetition_token_1.rb ├── 3-repetition_token_2.rb ├── 4-repetition_token_3.rb ├── 5-beginning_and_end.rb ├── 6-phone_number.rb ├── 7-OMG_WHY_ARE_YOU_SHOUTING.rb ├── README.md └── text_messages.log ├── 0x07-networking_basics ├── 0-OSI_model ├── 1-types_of_network ├── 2-MAC_and_IP_address ├── 3-UDP_and_TCP ├── 4-TCP_and_UDP_ports ├── 5-is_the_host_on_the_network └── README.md ├── 0x08-networking_basics_2 ├── 0-change_your_home_IP ├── 1-show_attached_IPs ├── 100-port_listening_on_localhost └── README.md ├── 0x09-web_infrastructure_design ├── 0-simple_web_stack.jpg ├── 0-simple_web_stack.pdf ├── 1-distributed_web_infrastructure.jpg ├── 1-distributed_web_infrastructure.pdf ├── 2-secured_and_monitored_web_infrastructure.jpg ├── 2-secured_and_monitored_web_infrastructure.pdf ├── 3-scale_up.jpg ├── 3-scale_up.pdf └── README.md ├── 0x0A-configuration_management ├── 0-create_a_file.pp ├── 1-install_a_package.pp ├── 2-execute_a_command.pp ├── README.md └── killmenow ├── 0x0B-ssh ├── 0-use_a_private_key ├── 1-create_ssh_key_pair ├── 100-puppet_ssh_config.pp ├── 2-ssh_config └── README.md ├── 0x0C-web_server ├── 0-transfer_file ├── 1-install_nginx_web_server ├── 2-setup_a_domain_name ├── 3-redirection ├── 4-not_found_page_404 ├── 7-puppet_install_nginx_web_server.pp └── README.md ├── 0x0D-web_stack_debugging_0 ├── 0-give_me_a_page └── README.md ├── 0x0E-web_stack_debugging_1 ├── 0-nginx_likes_port_80 ├── 1-debugging_made_short └── README.md ├── 0x0F-load_balancer ├── 0-custom_http_response_header ├── 1-install_load_balancer ├── 2-puppet_custom_http_response_header.pp └── README.md ├── 0x10-https_ssl ├── 0-world_wide_web ├── 1-haproxy_ssl_termination ├── 100-redirect_http_to_https └── README.md ├── 0x11-what_happens_when_your_type_google_com_in_your_browser_and_press_enter ├── 0-blog_post ├── 1-what_happen_when_diagram └── README.md ├── 0x12-web_stack_debugging_2 ├── 0-iamsomeoneelse ├── 1-run_nginx_as_nginx ├── 100-fix_in_7_lines_or_less └── README.md ├── 0x13-firewall ├── 0-block_all_incoming_traffic_but ├── 100-port_forwarding └── README.md ├── 0x14-mysql ├── 4-mysql_configuration_primary ├── 4-mysql_configuration_replica ├── 5-mysql_backup └── README.md ├── 0x15-api ├── 0-gather_data_from_an_API.py └── README.md ├── README.md └── attack_is_the_best_defense ├── 0-sniffing ├── 1-dictionary_attack ├── README.md └── user_authenticating_into_server /.gitignore: -------------------------------------------------------------------------------- 1 | *~ -------------------------------------------------------------------------------- /0x00-shell_basics/0-current_working_directory: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | pwd 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/1-listit: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ls 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/10-back: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cd - 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/100-lets_move: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | mv [[:upper:]]* /tmp/u/ 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/101-clean_emacs: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | rm *~ 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/102-tree: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | mkdir -p welcome/to/holberton 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/103-commas: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ls -amp | sort -d 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/11-lists: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ls -la . .. /boot 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/12-file_type: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | file /tmp/iamafile 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/13-symbolic_link: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ln -s /bin/ls __ls__ 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/14-copy_html: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cp -un *.html ../ 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/2-bring_me_home: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cd ~ 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/3-listfiles: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ls -l 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/4-listmorefiles: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ls -la 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/5-listfilesdigitonly: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ls -lan 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/6-firstdirectory: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | mkdir /tmp/holberton 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/7-movethatfile: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | mv /tmp/betty /tmp/holberton/ 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/8-firstdelete: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | rm /tmp/holberton/betty 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/9-firstdirdeletion: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | rmdir /tmp/holberton 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/README.md: -------------------------------------------------------------------------------- 1 | # 0x00 Shell Basics 2 | 3 | ## Resources 4 | 5 | - LinuxCommand.org [What is "the Shell"?](http://linuxcommand.org/lc3_lts0010.php). 6 | - [Read the Manual](http://linuxcommand.org/lc3_man_pages/man1.html). 7 | - [Keyboard Shortcuts for Bash](https://www.howtogeek.com/howto/ubuntu/keyboard-shortcuts-for-bash-command-shell-for-ubuntu-debian-suse-redhat-linux-etc/). 8 | 9 | ## Tasks 10 | 11 | 0. [Where am I?](./0-current_working_directory) : A script that prints the absolute path of the current working directory. 12 | 1. [What's in there?](./1-listit) : A script that displays the contents of your current directory. 13 | 2. [There is no place like home](./2-bring_me_home) : A script that changes the working directory to the user's home directory. 14 | 3. [The long format](./3-listfiles) : A script that displays the current directory contents in a long format. 15 | 4. [Hidden files](./4-listmorefiles) : A script that displays the current directory contents including hidden files. 16 | 5. [I loce numbers](./5-listfilesdigitonly) : A script that displays the current directory contents, using long format, while displaying group IDs in numeral and show hidden files. 17 | 6. [Welcome holberton](./6-firstdirectory) : A script that will create a directory named `holberton` in the `/tmp/` directory. 18 | 7. [Betty in Holberton](./7-movethatfile) : A scipt that will move a file called `betty` from home to the new directory created above. 19 | 8. [Bye bye Betty](./8-firstdelete) : A script that will delete file `betty` from the new location. 20 | 9. [Bye bye Holberton](./9-firstdirdeletion) : A script that will delete the directory `holberton` that is in the `/tmp/` directory path. 21 | 10. [Back to the future](./10-back) Change working directory to the previous one. 22 | 11. [Lists](./11-lists) List all files (*even ones with names beginning with a period character, which are normally hidden*) in the current directory and the parent of the working directory and the /boot directory (in this order), in long format. 23 | 12. [File type](./12-file_type) A script that prints the type of the named file `iamafile`. The `iamafile` will be in the `/tmp/` directory when we will run your script. 24 | 13. [We are symbols, and inhabit symbols](./13-symbolic_link) Create a symbolic link to `/bin/ls`, named `__ls__`. The symbolic link should be created in the current working directory. 25 | 14. [Copy HTML files](./14-copy_html) Create a script that copies all `html` files from the current working directory to the parent working directory while only copying files that did not exist. 26 | 15. [Let's move](./100-lets_move) A script that moves all files beginning with an uppercase letter to the directory `/tmp/u`. 27 | 16. [Clean Emacs](./101-clean_emacs) A script that deletes all files in the current directory that end with the character `~`. 28 | 17. [Tree](./102-tree) A script that creates the directory `welcome/`, `welcome/to/` and `welcome/to/holberton`. 29 | 18. [Life is a series of commas, not periods](./103-commas) A script that lists all the files and directories of the current directory separated by commas `,`. 30 | 19. [File type: Holberton](./holberton.mgc) Create a magic file `holberton.mgc` that can be used with the command `file` to detect `Holberton` data files always contain the string `HOLBERTON` at offset 0. 31 | -------------------------------------------------------------------------------- /0x00-shell_basics/holberton.mgc: -------------------------------------------------------------------------------- 1 | 0 string HOLBERTON Holberton data 2 | !:mime Holberton -------------------------------------------------------------------------------- /0x01-shell_permissions/0-iam_betty: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | su betty 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/1-who_am_i: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | whoami 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/10-mirror_permissions: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chmod --reference=olleh hello 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/100-change_owner_and_group: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chown betty:holberton * 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/101-symbolic_link_permissions: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chown -h betty:holberton _hello 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/102-if_only: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chown --from=guillaume betty hello 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/103-Star_Wars: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | telnet towel.blinkenlights.nl 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/11-directories_permissions: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chmod -R +X . 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/12-directory_permissions: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | mkdir -m 751 dir_holberton 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/13-change_group: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chgrp holberton hello 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/2-groups: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | groups 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/3-new_owner: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chown betty hello 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/4-empty: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | touch hello 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/5-execute: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chmod u+x hello 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/6-multiple_permissions: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chmod ug+x,o+r hello 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/7-everybody: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chmod +x hello 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/8-James_Bond: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chmod 007 hello 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/9-John_Doe: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chmod 753 hello 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/README.md: -------------------------------------------------------------------------------- 1 | # 0x01 Shell Permissions 2 | 3 | ## Resources 4 | 5 | - LinuxCommand.org [Permissions](http://linuxcommand.org/lc3_lts0090.php). 6 | 7 | ## Tasks 8 | 9 | 0. [My name is Betty](./0-iam_betty) : A script that switches the current user to the user betty. 10 | 1. [Who am I](./1-who_am_i) : A script that prints the effective username of the current user. 11 | 2. [Groups](./2-groups) : A script that prints all the groups the current user is part of. 12 | 3. [New owner](./3-new_owner) : A script that changes the owner of the file `hello` to the user `betty`. 13 | 4. [Empty!](./4-empty) : A script that creates an empty file called `hello`. 14 | 5. [Execute](./5-execute) : A script that adds execute permission to the owner of the file `hello`. 15 | 6. [Multiple permissions](./6-multiple_permissions) : A script that adds execute permission to the owner and the group owner, and read permission to the other users, to the file `hello`. 16 | 7. [Everybody!](./7-everybody) : A script that adds execution permissions to the owner, the group owner and the other users, to the file `hello`. 17 | 8. [James Bond](./8-James_Bond) : A script that gives the gives the rest of the users permission and removes all permission for the owner and the group owner. 18 | 9. [John Doe](./9-John_Doe) : A script that sets the mode of the file `hello`; where owner has all the permissions set, group owner has execute permissions set and others have only write and read permissions set. 19 | 10. [Look in the mirror](./10-mirror_permissions) : A script that sets the mode of the file `hello` the same as `olleh`'s mode. 20 | 11. [Directories](./11-directories_permissions) : A script that adds execute permission to all subdirectories of the current directory for the owner, the group owner and all other users. (**NB:** *Regular files should not be changed.*) 21 | 12. [More directories](./12-directory_permissions) : A script that creates a directory called `dir_holberton` with permissions **751** in the working directory. 22 | 13. [Change group](./13-change_group) : A script that changes the group owner to `holberton` for the file `hello`. 23 | 14. [Owner and group](./100-change_owner_and_group) : A script that changes the owner to `betty` and the group owner to `holberton` for all the files and directories in the working directory. 24 | 15. [Symbolic links](./101-symbolic_link_permissions) : A script that changes the owner and the group owner of `_hello` to `betty` and `holberton` respectively. 25 | 16. [If only](./102-if_only) : A script that changes the owner of the file `hello` to `betty` only if it is owned by the user `guillaume`. 26 | 17. [Star Wars](./103-Star_Wars) : A script that will play the StarWars IV episode in the terminal. 27 | -------------------------------------------------------------------------------- /0x02-shell_redirections/0-hello_world: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "Hello, World" 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/1-confused_smiley: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "\"(Ôo)'" 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/10-no_more_js: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | find . -name '*.js' -type f -delete 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/100-empty_casks: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | find . -empty -printf '%f\n' 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/101-gifs: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | find -type f -name "*.gif" | rev | cut -d "/" -f 1 | cut -d '.' -f 2- | rev | LC_ALL=C sort -f 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/102-acrostic: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cut -c 1 | paste -s -d '' 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/103-the_biggest_fan: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | tail -n +2 | cut -f -1 | sort -k 1 | uniq -c | sort -rnk 1 | head -n 11 | rev | cut -d ' ' -f -1 | rev 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/11-directories: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | find . -mindepth 1 -type d | wc -l 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/12-newest_files: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ls -t | head -n 10 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/13-unique: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | sort | uniq -u 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/14-findthatword: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | grep root /etc/passwd 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/15-countthatword: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | grep bin /etc/passwd | wc -l 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/16-whatsnext: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | grep -A 3 'root' /etc/passwd 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/17-hidethisword: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | grep -v bin /etc/passwd 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/18-letteronly: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | grep '^[[:upper:]]\|^[[:lower:]]' /etc/ssh/sshd_config 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/19-AZ: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | tr Ac Ze 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/2-hellofile: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cat /etc/passwd 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/20-hiago: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | tr -d cC 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/21-reverse: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | rev 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/22-users_and_homes: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cut -d':' -f1,6 /etc/passwd | sort 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/3-twofiles: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cat /etc/{passwd,hosts} 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/4-lastlines: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | tail -n 10 /etc/passwd 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/5-firstlines: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | head -n 10 /etc/passwd 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/6-third_line: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cat iacta | head -n 3 | tail -n 1 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/7-file: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "Holberton School" > "\*\\\'\"Holberton School\"\'\\\*$\?\*\*\*\*\*:)" 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/8-cwd_state: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ls -la > ls_cwd_content 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/9-duplicate_last_line: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | tail -n 1 iacta >> iacta 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/README.md: -------------------------------------------------------------------------------- 1 | # 0x002 Shell, I/O Redirections and Filters 2 | 3 | ## Resources 4 | 5 | - LinuxCommand.Org [I/O Redirection](http://linuxcommand.org/lc3_lts0070.php). 6 | - BashGuide [SpecialCharacters](http://mywiki.wooledge.org/BashGuide/SpecialCharacters). 7 | 8 | ## Tasks 9 | 10 | 0. [Hello World](./0-hello_world) : A script that prints `Hello, World`, followed by a new line to the standard output. 11 | 1. [Confused smiley](./1-confused_smiley) : A script that displays a confused smiley: `"(Ôo)'`. 12 | 2. [Let's display a file](./2-hellofile) : A script that displays the content of the `/etc/passwd` file. 13 | 3. [What about 2?](./3-twofiles) : A scipt that displays content of `/etc/passwd` and `/etc/hosts`. 14 | 4. [Last lines of a file](./4-lastlines) : A script that displays the last 10 lines of `/etc/passwd`. 15 | 5. [I'd prefer the first ones actually](./5-firstlines) : A scipt that displays the first 10 lines of `etc/passwd`. 16 | 6. [Line #2](./6-third_line) : A script that displays the third line of the file `iacta`. 17 | - The file `iacta` will be in the working directory and you are not allowed to use `sed`. 18 | 7. [It is a good file that cuts iron without making a noise](./7-file) : A script that creates a file named exactly `\*\\'"Holberton School"\'\\*$\?\*\*\*\*\*:)` containing the text `Holberton School` ending by a new line. 19 | - For this challenge, remember to use a single backslash `\` to escape special characters and double backslash `\\` to escape the backslash itself. 20 | 8. [Save current state of directory](./8-cwd_state) : A script that writes into the file `ls_cwd_content` the result of the command `ls -la`. If the file `ls_cwd_content` already exists, it should be overwritten. If the file `ls_cwd_content`does not exist, create it. 21 | 9. [Duplicate last line](./9-duplicate_last_line) : A script that duplicates the last line of the file `iacta`. 22 | 10. [No more javascript](./10-no_more_js) : A script that deletes all the regular files (not the directories) with a `.js` extension that are present in the current directory and all its subfolders. 23 | 11. [Don't just count your directories, make your directories count](./11-directories) : A script that counts the number of directories and sub-directories in the current directory. 24 | - The current and present directories should not be taken into account. 25 | - Hidden directories should be counted. 26 | - **Solution:** `mindepth 1` ; To exclude root directory 27 | - **Others:** `maxdepth 1` ; To avoid parsing sub directories. (*you may need this in future.*) 28 | 12. [Whats12's new](./12-newest_files) : A script that prints the 10 newest files in the current directory. 29 | - The output should be; one file per line and sorted from the newest to the oldest. 30 | 13. [Being unique is better than being perfect](./13-unique) : A script that takes a list of words as input and prints only words that appear exactly once. 31 | - Input and Output format is; `One word per line`. 32 | - Words should be sorted. (use this [list](./list) as your input to see if the challenge will work. 😊) `cat list | ./13-unique` 33 | 14. [It must be in that file](./14-findthatword) : A script that prints lines containing the pattern `"root"` from the file `/etc/passwd`. 34 | 15. [Count that word](./15-countthatword) : A script that displays the number of lines that contain the pattern `"bin"` in the file `/etc/passwd`. 35 | 16. [What's next?](./16-whatsnext) : A script that containing the pattern `"root"` and 3 lines after them in the file `/etc/passwd`. 36 | - `B` : This shows the lines before your pattern match. 37 | - `A` : This shows the lines after your pattern match. 38 | 17. [I hate bins](./17-hidethisword) : A script that displays all the lines in the file `/etc/passwd` that do not contain the pattern `"bin"`. 39 | 18. [Letters only please](./18-letteronly) : A script that displays all lines of the file `/ect/ssh/sshd_config` starting with a letter, including capital letters as well. 40 | - This also works : `grep ^[[:alpha:]] /etc/ssh/sshd_config` 41 | 19. [A to Z](./19-AZ) : A script that replaces all characters `A` and `C` from input to `Z` and `E` respectively. 42 | 20. [Without C, you would live in hiago](./20-hiago) : A script that removes all letters `c` and `C` from input. 43 | 21. [esreveR](./21-reverse) : A script that reverse its input. 44 | 22. [DJ Cut Killer](./22-users_and_homes) : A scipt that displays all users and their home directories, sorted by users, based on the `/etc/passwd` file. 45 | 23. [Empty casks make the most noise](./100-empty_casks) : A script that finds all empty files and directories in the current directory and all sub-directories. 46 | - Only names of the files and directories should be displayed (not the entire path.) 47 | - Hidden files should be listed also, one file name per line and the listing should end with a new line. 48 | - You are not allowed to use `basename`, `grep`, `egrep`, `fgrep` or `rgrep`. 49 | 24. [A gif is worth ten thousand words](./101-gifs) : A script that lists all the files with a `.gif` extension in the current directory and all its sub-directories. 50 | - Hidden files should be listed. 51 | - Only regular files (not directories) should be listed. 52 | - The names of the files should be displayed without their extensions. 53 | - The files should be sorted by byte values, but case-insensitive (file `aaa` should be listed before file `bbb`, file `.b` should be listed before file `a`, and file `Rona` should be listed after file `jay`) 54 | - One file name per line. 55 | - The listing should end with a new line. 56 | - You are not allowed to use `basename`, `grep`, `egrep`, `fgrep` or `rgrep`. 57 | 25. [Acrostic](./102-acrostic) : A script that decodes acrostics that use the first letter of each line. 58 | - What to decode: `An acrostic is a poem (or other form of writing) in which the first letter (or syllable, or word) of each line (or paragraph, or other recurring feature in the text) spells out a word, message or the alphabet. The word comes from the French acrostiche from post-classical Latin acrostichis). As a form of constrained writing, an acrostic can be used as a mnemonic device to aid memory retrieval.` [Read more here](https://en.wikipedia.org/wiki/Acrostic) 59 | - The **‘decoded’** message has to end with a new line. 60 | - You are not allowed to use `grep`, `egrep`, `fgrep` or `rgrep`. 61 | 26. [The biggest fan](./103-the_biggest_fan) : A script that parses web servers logs in TSV format as input and displays the 11 hosts or IP addresses which did the most requests. 62 | - Download this file: `wget http://indeedeng.github.io/imhotep/files/nasa_19950801.tsv` 63 | - Run command this way: `./103-the_biggest_fan < nasa_19950801.tsv`. 64 | - Order by number of requests, most active host or IP at the top. 65 | - You are not allowed to use `grep`, `egrep`, `fgrep` or `rgrep`. 66 | -------------------------------------------------------------------------------- /0x02-shell_redirections/list: -------------------------------------------------------------------------------- 1 | C# 2 | C 3 | Javascript 4 | Perl 5 | PHP 6 | PHP 7 | ASP 8 | R 9 | Go 10 | C# 11 | C++ 12 | R 13 | Perl 14 | Javascript 15 | Javascript 16 | Python 17 | Javascript 18 | Javascript 19 | Javascript 20 | Java 21 | Java 22 | Python 23 | Javascript 24 | Javascript 25 | Javascript 26 | ASP 27 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/0-alias: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | alias ls="rm *" 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/1-hello_you: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "hello $USER" 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/10-love_exponent_breath: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo $(($BREATH ** $LOVE)) 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/100-decimal_to_hexadecimal: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | printf "%x\n" $DECIMAL 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/101-rot13: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | tr 'A-Za-z' 'N-ZA-Mn-za-m' 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/102-odd: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | paste -d, - - | cut -d, -f1 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/103-water_and_stir: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | printf "%o\n" $(( $((5#$(echo $WATER | tr water 01234))) + $((5#$(echo $STIR | tr stir. 01234))) )) | tr 01234567 behlnort 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/11-binary_to_decimal: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo $((2#$BINARY)) 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/12-combinations: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo {a..z}{a..z} | tr ' ' '\n' | grep -v 'oo' 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/13-print_float: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | printf "%.2f\n" $NUM 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/2-path: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | export PATH=${PATH}:/action 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/3-paths: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo $PATH | tr ":" "\n" | wc -l 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/4-global_variables: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | printenv 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/5-local_variables: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | declare 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/6-create_local_variable: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | BETTY="Holberton" 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/7-create_global_variable: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | export HOLBERTON="Betty" 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/8-true_knowledge: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo $(($TRUEKNOWLEDGE + 128)) 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/9-divide_and_rule: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo $(($POWER / $DIVIDE)) 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/README.md: -------------------------------------------------------------------------------- 1 | # 0x03 Shell, init files, variables and expansions 2 | 3 | ## Resources 4 | 5 | - Shell [Expansion](http://linuxcommand.org/lc3_lts0080.php). 6 | - Shell [Arithmetic](https://www.gnu.org/software/bash/manual/html_node/Shell-Arithmetic.html). 7 | - Bash [Variable](https://tldp.org/LDP/Bash-Beginners-Guide/html/sect_03_02.html). 8 | - Bash [Shell initialization files](https://tldp.org/LDP/Bash-Beginners-Guide/html/sect_03_01.html). 9 | - [The alias Command](http://www.linfo.org/alias.html). 10 | 11 | ## Tasks 12 | 13 | 0. [\](./0-alias) : A script that creates an alias. 14 | - Name of alias: `ls` 15 | - Value: `rm *` 16 | 1. [Hello you](./1-hello_you) : A script that prints `hello user`, where user is the current Linux user. 17 | 2. [The path to success is to take massive, determined action](./2-path) : A script that adds `/action` to the `PATH`. `/action` should be the last directory the shell looks into when looking for a program. 18 | 3. [If the path be beautiful, let us not ask where it leads](./3-paths) : A script that counts the number of directories in the `PATH`. 19 | 4. [Global variables](./4-global_variables) : A script that prints all the enviroment variables. 20 | 5. [Local variables ](./5-local_variables) : A script that lists all local variables and enviroment variables, and functions. 21 | - Name of variable : `HOLBERTON` 22 | - Value : `Betty` 23 | 6. [Local variable](./6-create_local_variable) : A script that creates a new local variable. 24 | 7. [Global variable](./7-create_global_variable) : A script that creates a new global variable. 25 | - Name of variable : `HOLBERTON` 26 | - Value : `Betty` 27 | 8. [Every addition to true knowledge is an addition to human power](./8-true_knowledge) : A script that prints the results of the addition of 128 with the value stored in the enviroment variable `TRUEKNOWLEDGE`, followed by a new line. 28 | - Remember to export variable TRUEKNOWLEDGE : `export TRUEKNOWLEDGE=1209` 29 | - Run command this way: `./8-true_knowledge | cat -e` 30 | 9. [Divide and rule](./9-divide_and_rule) : A script that prints the result of `POWER` divide by `DIVIDE`, followed by a new line. 31 | - `POWER` and `DIVIDE` are environment variables. 32 | - Variables values; 33 | - export POWER=42784 34 | - export DIVIDE=32 35 | - Run command this way: `./9-divide_and_rule | cat -e` 36 | 10. [Love is anterior to life, posterior to death, initial of creation, and the exponent of breath](./10-love_exponent_breath) : A script that displays the result of `BREATH` to the power of `LOVE`. 37 | - `BREATH` and `LOVE` are enviroment variables. 38 | - The script should display the result, followed by a new line. 39 | 11. [There are 10 types of people in the world -- Those who understand binary, and those who don't](./11-binary_to_decimal) : A script that converts a number from base 2 to base 10. 40 | - The number in base 2 is stored in the enviroment variable `BINARY`. 41 | - The script should display the number in base 10, followed by a new line. 42 | 12. [Combination](./12-combinations) : A script that prints all possible combinations of two letters, except `oo`. 43 | - Letters are lower cases, from `a` to `z`. 44 | - One combination per line. 45 | - The output should be alpha ordered, starting with `aa`. 46 | - Do not print `oo`. 47 | - Your script file should contain maximum 64 characters. 48 | 13. [Floats](./13-print_float) : A script that prints a number with two decimal places, followed by a new line. 49 | - The number will be stored in the enviroment variable `NUM`. 50 | 14. [Decimal to Hexadecimal](./100-decimal_to_hexadecimal) : A script that converts a number from base 10 to base 16. 51 | - The number is base 10 is stored in the enviroment variable `DECIMAL`. 52 | - The script should display the number in base 16, followed by a new line. 53 | 15. [Everyone is a proponent of strong encryption](./101-rot13) : A script that encodes and decodes text using the rot13 encryption. Assume ASCII. 54 | 16. [The eggs of the brood need to be an odd number](./102-odd) : A script that prints every other line from the input, starting with the first line. 55 | 17. [I'm an instant star. Just add water and stir.](./103-water_and_stir) : A script that adds the two numbers stored in the enviroment variables `WATER` and `STIR` and prints the results. 56 | - `WATER` is in base `water`. 57 | - `STIR` is in base `stir`. 58 | - The result should be in base `behlnort`. 59 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/0-RSA_public_key.pub: -------------------------------------------------------------------------------- 1 | ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDjr22fiOaHPnXe4Nhlw+E/vZS5Pq7Y4LhaBWtcsXmxQjeTLy4KwdCyuZ2SALk9cS38sv6uMRTM3CVaC18O4AVylN7bAM8nPwVoIBqAr9ML75Q9qj+Abm8Vg8tSfYP4QS8MTbGeeyZdiq6nXWlLYVk/Jdf+ux+riHyW31mkpJyoQw/NU8I7psoa6xAS2c37oMKepi6lmYEnA7oZDE2PWt1oC8dqAqsC4Gyrz7veCj6xbGutpuo9cmuaoYmLnjdUr9n1gcsRWzrJhBYD6RRzLtSkDI8Qpd2pG5Bo9TFJg2stBkTYr9co4IuPrdSn2alB/Nl4laY9nzPD20FKDaRYfTiDMX6j64bkYWdeS3QYy/LzP7J5a4DrSxD/Gs5LOpUy0b4tk0OcgdsGeWHS3fJhlJvPyKyCLoJTqujGX7lc20CRD7DxPyWObQAbmXB74HcwuY+l0RsI/dyk8hCQTpyGlhudIM8em7LDFm9g+GN4FWeDAdfG1JduV5isGiu1ayOZPf0= th3_lab@th3d3n 2 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/1-for_best_school: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # prints a string 10 times using for loop 3 | 4 | for ((i = 1; i <= 10; i++)); do 5 | echo "Best School" 6 | done 7 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/10-fizzbuzz: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Fizzbuzz 3 | 4 | n=1 5 | 6 | while [ "$n" -le 100 ]; do 7 | 8 | 9 | if ! (( n % 3 )) && ! (( n % 5 )); then 10 | echo "FizzBuzz" 11 | elif ! (( n % 3 )); then 12 | echo "Fizz" 13 | elif ! (( n % 5 )); then 14 | echo "Buzz" 15 | else 16 | echo "$n" 17 | fi 18 | 19 | ((n++)) 20 | done 21 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/100-read_and_cut: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # read and cat 3 | 4 | file="/etc/passwd" 5 | 6 | while IFS= read -r line; do 7 | echo "$line" | cut -d ':' -f1,3,6 8 | done < "$file" 9 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/101-tell_the_story_of_passwd: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Tell the story of passwd 3 | 4 | file="/etc/passwd" 5 | 6 | while IFS= read -r line; do 7 | user=$(echo "$line" | cut -d ':' -f1) 8 | gid=$(echo "$line" | cut -d ':' -f4) 9 | dir=$(echo "$line" | cut -d ':' -f6) 10 | shell=$(echo "$line" | cut -d ':' -f7) 11 | uid=$(echo "$line" | cut -d ':' -f3) 12 | pass=$(echo "$line" | cut -d ':' -f2) 13 | info=$(echo "$line" | cut -d ':' -f5) 14 | 15 | echo "The user $user is part of the $gid gang, lives in $dir and rides $shell. $uid's place is protected by the passcode $pass, more info about the user here: $info" 16 | done < "$file" 17 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/102-lets_parse_apache_logs: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # parse apache logs and show ip and status code 3 | 4 | awk '{print $1,$9}' apache-access.log 5 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/103-dig_the-data: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Dig the data 3 | 4 | awk '{print $1,$9}' apache-access.log | sort | uniq -c | sort -r 5 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/2-while_best_school: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # prints a string 10 times using while loop 3 | 4 | i=0 5 | 6 | while [ "$i" -lt 10 ]; do 7 | echo "Best School" 8 | ((i++)) 9 | done 10 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/3-until_best_school: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # print a string 10 times using until loop 3 | 4 | i=0 5 | 6 | until false; do 7 | echo "Best School" 8 | ((i++)) 9 | if [[ $i -lt 10 ]]; then 10 | continue 11 | else 12 | break 13 | fi 14 | done 15 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/4-if_9_say_hi: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # prints a string 10 times using while loop and on the ninth iteration it prints hi 3 | 4 | i=1 5 | 6 | while [ "$i" -lt 11 ]; do 7 | echo "Best School" 8 | 9 | # if statement to print Hi when i is 9 10 | if [ "$i" -eq 9 ]; then 11 | echo "Hi" 12 | fi 13 | 14 | ((i++)) 15 | done 16 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/5-4_bad_luck_8_is_your_chance: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 4 bad luck, 8 is your chance 3 | 4 | i=1 5 | 6 | while [ "$i" -lt 11 ]; do 7 | 8 | # if 4 bad luck elif 8 good luck 9 | if [ "$i" -eq 4 ]; then 10 | echo "bad luck" 11 | elif [ "$i" -eq 8 ]; then 12 | echo "good luck" 13 | else 14 | echo "Best School" 15 | fi 16 | 17 | ((i++)) 18 | done 19 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/6-superstitious_numbers: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # cultures with numbers ... 3 | 4 | i=1 5 | 6 | while [ "$i" -lt 21 ]; do 7 | 8 | case "$i" in 9 | 4) 10 | echo "$i" 11 | echo "bad luck from China" 12 | ;; 13 | 9) 14 | echo "$i" 15 | echo "bad luck from Japan" 16 | ;; 17 | 17) 18 | echo "$i" 19 | echo "bad luck from Italy" 20 | ;; 21 | *) 22 | echo "$i" 23 | ;; 24 | esac 25 | 26 | ((i++)) 27 | done 28 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/7-clock: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # display time for 12 hours and 59 minutes 3 | 4 | hour=0 5 | 6 | while [ "$hour" -le 12 ]; do 7 | echo "Hour: $hour" 8 | 9 | minute=1 10 | 11 | while [ "$minute" -lt 60 ]; do 12 | echo "$minute" 13 | minute=$((minute + 1)) 14 | done 15 | 16 | hour=$((hour + 1)) 17 | done 18 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/8-for_ls: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # ls using for loop 3 | 4 | for file in *; do 5 | echo "$file" | cut -d '-' -f 2; 6 | done 7 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/9-to_file_or_not_to_file: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # alx school file checker 3 | 4 | file="school" 5 | 6 | # checks if file exists 7 | if [ -e "$file" ]; then 8 | 9 | echo "school file exists" 10 | 11 | # checks if file is empty 12 | if [ ! -s "$file" ]; then 13 | echo "school file is empty" 14 | 15 | # checks if file is a regular file 16 | if [ -f "$file" ]; then 17 | echo "school is a regular file" 18 | fi 19 | 20 | else 21 | 22 | echo "school file is not empty" 23 | 24 | # checks if file is a regular file 25 | if [ -f "$file" ]; then 26 | echo "school is a regular file" 27 | fi 28 | 29 | fi 30 | 31 | else 32 | 33 | echo "school file does not exist" 34 | 35 | fi 36 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/README.md: -------------------------------------------------------------------------------- 1 | # 0x04. Loops, conditions and parsing 2 | 3 | ## Resource 4 | 5 | - [Loops sample](https://tldp.org/LDP/Bash-Beginners-Guide/html/sect_09_01.html) 6 | - [Variable assignment and arithmetic](https://tldp.org/LDP/abs/html/ops.html) 7 | - [Comparison operators](https://tldp.org/LDP/abs/html/comparison-ops.html) 8 | - [File test operators](https://tldp.org/LDP/abs/html/fto.html) 9 | - [Make your scripts portable](https://www.cyberciti.biz/tips/finding-bash-perl-python-portably-using-env.html) 10 | 11 | ## Tasks 12 | 13 |
14 | 0. Create a SSH RSA key pair
15 | image
16 | 25 |
26 | 27 |
28 | 1. For Best School loop
29 | image 30 |
31 | 32 |
33 | 2. While Best School loop
34 | image 35 |
36 | 37 |
38 | 3. Until Best School loop
39 | image 40 |
41 | 42 |
43 | 4. If 9, say Hi!
44 | image 45 |
46 | 47 |
48 | 5. 4 bad luck, 8 is your chance
49 | image
50 | 58 |
59 | 60 |
61 | 6. Superstitious numbers
62 | image 63 |
64 | 65 |
66 | 7. Clock
67 | image 68 |
69 | 70 |
71 | 8. For ls
72 | image 73 |
74 | 75 |
76 | 9. To file, or not to file
77 | image 78 |
79 | 80 |
81 | 10. FizzBuzz
82 | image 83 |
84 | 85 |
86 | 11. Read and cut
87 | image 88 |
89 | 90 |
91 | 12. Tell the story of passwd
92 | image 93 | 101 |
102 | 103 |
104 | 13. Let's parse Apache logs
105 | image 106 | 115 |
116 | 117 |
118 | 14. Dig the data
119 | image 120 |
121 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/0-what-is-my-pid: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # my pid 3 | 4 | sleep 5 & 5 | echo "$!" 6 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/1-list_your_processes: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # list all my currently running processes 3 | 4 | # source: https://linuxize.com/post/ps-command-in-linux/ 5 | ps -auxf 6 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/100-process_and_pid_file: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Process and PID file 3 | 4 | file="/var/run/myscript.pid" 5 | 6 | if [ ! -e "$file" ]; then 7 | touch "$file" 8 | fi 9 | 10 | sleep 2 & 11 | 12 | echo "$!" > "$file" 13 | 14 | # prints I hate the kill command, deletes the file and exits when receiving a SIGTERM or SIGQUIT signal 15 | trap 'echo "I hate the kill command"; rm "$file"; exit' SIGTERM SIGQUIT 16 | 17 | # prints Y U no love me?! when receiving a SIGINT signal 18 | trap "echo Y U no love me?!" SIGINT 19 | 20 | while true; do 21 | echo "To infinity and beyond" 22 | sleep 2 23 | done 24 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/101-manage_my_process: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # manages manage_my_process by either starting it, stopping it or restarting it. 3 | 4 | command="$1" 5 | 6 | if [ -z "$command" ]; then 7 | echo "Usage: manage_my_process {start|stop|restart}" 8 | exit 9 | fi 10 | 11 | if [ "$command" == "start" ]; then 12 | 13 | bash ./manage_my_process & 14 | echo "$!" > /var/run/my_process.pid 15 | echo "manage_my_process started" 16 | 17 | elif [ "$command" == "stop" ]; then 18 | [ -e "/var/run/my_process.pid" ] && pkill -f './manage_my_process' && rm /var/run/my_process.pid 19 | echo "manage_my_process stopped" 20 | 21 | elif [ "$command" == "restart" ]; then 22 | 23 | "$0" stop >& /dev/null 24 | "$0" start >& /dev/null 25 | echo "manage_my_process restarted" 26 | 27 | else 28 | echo "Usage: manage_my_process {start|stop|restart}" 29 | fi 30 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/102-zombie.c: -------------------------------------------------------------------------------- 1 | #include "stdio.h" 2 | #include "stdlib.h" 3 | #include "unistd.h" 4 | 5 | /** 6 | * infinite_while - a function that runs forever and returns nothing 7 | * Return: 0 in the end 8 | */ 9 | int infinite_while(void) 10 | { 11 | while (1) 12 | { 13 | sleep(1); 14 | } 15 | return (0); 16 | } 17 | 18 | /** 19 | * main - the entry to a program that creats 5 zombie process 20 | * Return: 0 on sucess 21 | */ 22 | int main(void) 23 | { 24 | int children_processes = 0; 25 | pid_t pid; 26 | 27 | while (children_processes < 5) 28 | { 29 | pid = fork(); 30 | if (!pid) 31 | break; 32 | printf("Zombie process created, PID: %i\n", (int)pid); 33 | children_processes++; 34 | } 35 | if (pid != 0) 36 | infinite_while(); 37 | return (0); 38 | } 39 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/2-show_your_bash_pid: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # list all bash processes 3 | # shellcheck disable=SC2009 4 | ps -auxf | grep bash 5 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/3-show_your_bash_pid_made_easy: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # PID made easy 3 | 4 | pgrep -l bash 5 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/4-to_infinity_and_beyond: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # To infinity and beyond 3 | 4 | while true; do 5 | echo "To infinity and beyond" 6 | sleep 2 7 | done 8 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/5-dont_stop_me_now: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Don't stop me now 3 | 4 | pgrep -f 4-to_infinity_and_beyond | xargs kill 5 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/6-stop_me_if_you_can: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Stop me if you can 3 | 4 | pkill -f 4-to_infinity_and_beyond 5 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/67-stop_me_if_you_can: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Stop me if you can 3 | 4 | pkill -f 7-highlander 5 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/7-highlander: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Highlander 3 | 4 | # print I am invincible!!! when receiving a SIGTERM signal 5 | trap "echo I am invincible!!!" SIGTERM 6 | 7 | while true; do 8 | echo "To infinity and beyond" 9 | sleep 2 10 | done; 11 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/8-beheaded_process: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Beheaded process 3 | 4 | pgrep -f 7-highlander | xargs kill -9 5 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/README.md: -------------------------------------------------------------------------------- 1 | # 0x05. Processes and signals 2 | 3 | ## Resource 4 | 5 | - [Linux PID](http://www.linfo.org/pid.html) 6 | - [Linux process](https://www.thegeekstuff.com/2012/03/linux-processes-environment/) 7 | - [Linux signal](https://www.thegeekstuff.com/2012/03/linux-signals-fundamentals/) 8 | 9 | ## Tasks 10 | 11 |
12 | 0. What is my PID
13 | image 14 |
15 | 16 |
17 | 1. List your processes
18 | image 19 |
20 | 21 |
22 | 2. Show your Bash PID
23 | image 24 |
25 | 26 |
27 | 3. Show your Bash PID made easy
28 | image 29 |
30 | 31 |
32 | 4. To infinity and beyond
33 | image 34 |
35 | 36 |
37 | 5. Don't stop me now!
38 | image 39 |
40 | 41 |
42 | 6. Stop me if you can
43 | image 44 |
45 | 46 |
47 | 7. Highlander
48 | image 49 |
50 | 51 |
52 | 8. Beheaded process
53 | image 54 |
55 | 56 |
57 | 9. Beheaded process
58 | image 59 |
60 | 61 |
62 | 10. Process and PID file
63 | image 64 |
65 | 66 |
67 | 11. Manage my process
68 | image 69 | 80 |
81 | 82 |
83 | 12. Zombie
84 | image 85 | 92 |
93 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/manage_my_process: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # well well well 3 | 4 | file="/tmp/my_process" 5 | 6 | while true; do 7 | echo "I am alive!" >> "$file" 8 | sleep 2 9 | done 10 | -------------------------------------------------------------------------------- /0x06-regular_expressions/0-simply_match_school.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | puts ARGV[0].scan(/School/).join 3 | -------------------------------------------------------------------------------- /0x06-regular_expressions/1-repetition_token_0.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | puts ARGV[0].scan(/hbt{2,5}n/).join 3 | -------------------------------------------------------------------------------- /0x06-regular_expressions/100-textme.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | from = ARGV[0].scan(/from:(.*?)\]/) 4 | to = ARGV[0].scan(/to:(.*?)\]/) 5 | flags = ARGV[0].scan(/flags:(.*?)\]/) 6 | puts [from, to, flags].join(',') 7 | -------------------------------------------------------------------------------- /0x06-regular_expressions/2-repetition_token_1.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | puts ARGV[0].scan(/hb?tn/).join 3 | -------------------------------------------------------------------------------- /0x06-regular_expressions/3-repetition_token_2.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | puts ARGV[0].scan(/hbt+n/).join 3 | -------------------------------------------------------------------------------- /0x06-regular_expressions/4-repetition_token_3.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | puts ARGV[0].scan(/hbt*n/).join 3 | -------------------------------------------------------------------------------- /0x06-regular_expressions/5-beginning_and_end.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | puts ARGV[0].scan(/^h.n$/).join 3 | -------------------------------------------------------------------------------- /0x06-regular_expressions/6-phone_number.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | puts ARGV[0].scan(/^\d{10}$/).join 3 | -------------------------------------------------------------------------------- /0x06-regular_expressions/7-OMG_WHY_ARE_YOU_SHOUTING.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | puts ARGV[0].scan(/[A-Z]*/).join 3 | -------------------------------------------------------------------------------- /0x06-regular_expressions/README.md: -------------------------------------------------------------------------------- 1 | # 0x06. Regular expression 2 | 3 | ## Resource 4 | 5 |
6 | Regular Expression
7 | image 8 | 18 |
19 | 20 | - [Regular expressions - basics](https://www.slideshare.net/neha_jain/introducing-regular-expressions) 21 | - [Regular expressions - advanced](https://www.slideshare.net/neha_jain/advanced-regular-expressions-80296518) 22 | - [Rubular is your best friend](https://rubular.com/) 23 | - [Use a regular expression against a problem: now you have 2 problems](https://blog.codinghorror.com/regular-expressions-now-you-have-two-problems/) 24 | - [Learn Regular Expressions with simple, interactive exercises](https://regexone.com/) 25 | 26 | ## Tasks 27 | 28 |
29 | 0. Simply matching School
30 | image 31 |
32 | 33 |
34 | 1. Repetition Token #0
35 | image 36 |
37 | 38 |
39 | 2. Repetition Token #1
40 | image 41 |
42 | 43 |
44 | 3. Repetition Token #2
45 | image 46 |
47 | 48 |
49 | 4. Repetition Token #3
50 | image 51 |
52 | 53 |
54 | 5. Not quite HBTN yet
55 | image 56 |
57 | 58 |
59 | 6. Call me maybe
60 | image 61 |
62 | 63 |
64 | 7. OMG WHY ARE YOU SHOUTING?
65 | image 66 |
67 | 68 |
69 | 8. Textme
70 | image 71 | 78 |
79 | -------------------------------------------------------------------------------- /0x07-networking_basics/0-OSI_model: -------------------------------------------------------------------------------- 1 | 2 2 | 2 3 | -------------------------------------------------------------------------------- /0x07-networking_basics/1-types_of_network: -------------------------------------------------------------------------------- 1 | 3 2 | 2 3 | 1 4 | -------------------------------------------------------------------------------- /0x07-networking_basics/2-MAC_and_IP_address: -------------------------------------------------------------------------------- 1 | 2 2 | 1 3 | -------------------------------------------------------------------------------- /0x07-networking_basics/3-UDP_and_TCP: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 1 4 | -------------------------------------------------------------------------------- /0x07-networking_basics/4-TCP_and_UDP_ports: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # script that displays TCP and UDP listening ports 3 | 4 | netstat -l 5 | -------------------------------------------------------------------------------- /0x07-networking_basics/5-is_the_host_on_the_network: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # script that pings an IP address passed as an argument 3 | 4 | # ip variable 5 | IP="${1}" 6 | 7 | # filename variable 8 | fn=$(basename "${BASH_SOURCE[@]}") 9 | 10 | if ! [ "$IP" ]; then 11 | echo "Usage: ${fn} {IP_ADDRESS}" 12 | else 13 | ping -c 5 "${IP}" 14 | fi 15 | -------------------------------------------------------------------------------- /0x07-networking_basics/README.md: -------------------------------------------------------------------------------- 1 | # 0x07. Networking basics #0 2 | 3 | ## Resources 4 | 5 | - [OSI model](https://en.wikipedia.org/wiki/OSI_model) 6 | - [Different types of network](https://www.lifewire.com/lans-wans-and-other-area-networks-817376) 7 | - [LAN Network](https://en.wikipedia.org/wiki/Local_area_network) 8 | - [WAN Network](https://en.wikipedia.org/wiki/Wide_area_network) 9 | - [Internet](https://en.wikipedia.org/wiki/Internet) 10 | - [MAC address](https://whatismyipaddress.com/mac-address) 11 | - [What is an IP address](https://www.bleepingcomputer.com/tutorials/ip-addresses-explained/) 12 | - [Private and public address](https://www.iplocation.net/public-vs-private-ip-address) 13 | - [IPv4 and IPv6](https://www.webopedia.com/insights/ipv6-ipv4-difference/) 14 | - [Localhost](https://en.wikipedia.org/wiki/Localhost) 15 | - [TCP and UDP](https://www.howtogeek.com/190014/htg-explains-what-is-the-difference-between-tcp-and-udp/) 16 | - [TCP/UDP ports List](https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers) 17 | - [What is ping/ICMP](https://en.wikipedia.org/wiki/Ping_%28networking_utility%29) 18 | - [Positional parameters](https://wiki.bash-hackers.org/scripting/posparams) 19 | 20 | ## Tasks 21 | 22 |
23 | 0. OSI model
24 | image 25 |
26 | 27 |
28 | 1. Types of network
29 | image 30 |
31 | 32 |
33 | 2. MAC and IP address
34 | image 35 |
36 | 37 |
38 | 3. UDP and TCP
39 | image 40 |
41 | 42 |
43 | 4. TCP and UDP ports
44 | image 45 |
46 | 47 |
48 | 5. Is the host on the network
49 | image 50 |
51 | -------------------------------------------------------------------------------- /0x08-networking_basics_2/0-change_your_home_IP: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # changes the following domain resolve ips 3 | # localhost from 127.0.0.1 to 127.0.0.2 4 | # facebook.com from 157.240.11.35 to 8.8.8.8 5 | 6 | cp /etc/hosts ~/hosts.new 7 | echo "127.0.0.2 localhost" > ~/hosts.new 8 | echo "8.8.8.8 facebook.com" >> ~/hosts.new 9 | cp -f ~/hosts.new /etc/hosts 10 | -------------------------------------------------------------------------------- /0x08-networking_basics_2/1-show_attached_IPs: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays all acive IPv4 addresses on the machine. 3 | 4 | # a different way using ifconfig but now ip is a new command and ifconfig can be missing in some os 5 | #ifconfig | grep -Eo "inet (addr:)?([0-9]*\.){3}[0-9]*" | awk '{print $2}' 6 | 7 | ip -4 -o addr show | awk '{print $4}' | cut -d "/" -f 1 8 | 9 | -------------------------------------------------------------------------------- /0x08-networking_basics_2/100-port_listening_on_localhost: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # a script that listens on poer 98 on localhost 3 | 4 | nc -l localhost 98 5 | -------------------------------------------------------------------------------- /0x08-networking_basics_2/README.md: -------------------------------------------------------------------------------- 1 | # 0x08. Networking basics #1 2 | 3 | ## Resource 4 | 5 | - [What is localhost](https://en.wikipedia.org/wiki/Localhost) 6 | - [What is 0.0.0.0](https://en.wikipedia.org/wiki/0.0.0.0) 7 | - [What is the hosts file](https://www.makeuseof.com/tag/modify-manage-hosts-file-linux/) 8 | - [Netcat examples](https://www.thegeekstuff.com/2012/04/nc-command-examples/) 9 | 10 | ## Tasks 11 | 12 |
13 | 0. Change your home IP
14 | image 15 | 22 |
23 | 24 |
25 | 1. Show attached IPs
26 | image 27 |
28 | 29 |
30 | 2. Port listening on localhost
31 | image 32 |
33 | -------------------------------------------------------------------------------- /0x09-web_infrastructure_design/0-simple_web_stack.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iAmG-r00t/alx-system_engineering-devops/094b0b695ae36afe9cab41023ee0ce8573843ad4/0x09-web_infrastructure_design/0-simple_web_stack.jpg -------------------------------------------------------------------------------- /0x09-web_infrastructure_design/0-simple_web_stack.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iAmG-r00t/alx-system_engineering-devops/094b0b695ae36afe9cab41023ee0ce8573843ad4/0x09-web_infrastructure_design/0-simple_web_stack.pdf -------------------------------------------------------------------------------- /0x09-web_infrastructure_design/1-distributed_web_infrastructure.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iAmG-r00t/alx-system_engineering-devops/094b0b695ae36afe9cab41023ee0ce8573843ad4/0x09-web_infrastructure_design/1-distributed_web_infrastructure.jpg -------------------------------------------------------------------------------- /0x09-web_infrastructure_design/1-distributed_web_infrastructure.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iAmG-r00t/alx-system_engineering-devops/094b0b695ae36afe9cab41023ee0ce8573843ad4/0x09-web_infrastructure_design/1-distributed_web_infrastructure.pdf -------------------------------------------------------------------------------- /0x09-web_infrastructure_design/2-secured_and_monitored_web_infrastructure.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iAmG-r00t/alx-system_engineering-devops/094b0b695ae36afe9cab41023ee0ce8573843ad4/0x09-web_infrastructure_design/2-secured_and_monitored_web_infrastructure.jpg -------------------------------------------------------------------------------- /0x09-web_infrastructure_design/2-secured_and_monitored_web_infrastructure.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iAmG-r00t/alx-system_engineering-devops/094b0b695ae36afe9cab41023ee0ce8573843ad4/0x09-web_infrastructure_design/2-secured_and_monitored_web_infrastructure.pdf -------------------------------------------------------------------------------- /0x09-web_infrastructure_design/3-scale_up.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iAmG-r00t/alx-system_engineering-devops/094b0b695ae36afe9cab41023ee0ce8573843ad4/0x09-web_infrastructure_design/3-scale_up.jpg -------------------------------------------------------------------------------- /0x09-web_infrastructure_design/3-scale_up.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iAmG-r00t/alx-system_engineering-devops/094b0b695ae36afe9cab41023ee0ce8573843ad4/0x09-web_infrastructure_design/3-scale_up.pdf -------------------------------------------------------------------------------- /0x09-web_infrastructure_design/README.md: -------------------------------------------------------------------------------- 1 | # 0x09. Web infrastructure design 2 | 3 | ## Resource 4 | 5 | - [Web Infrastructure](https://youtu.be/lQNEW76KdYg) 6 | - [What is a database](https://searchdatamanagement.techtarget.com/definition/database) 7 | - [What’s the difference between a web server and an app server?](https://www.youtube.com/watch?v=S97eKyv2b9M) 8 | - [DNS record types](https://pressable.com/?s=DNS&post_type=knowledgebase) 9 | - [Single point of failure](https://en.wikipedia.org/wiki/Single_point_of_failure) 10 | - [How to avoid downtime when deploying new code](https://softwareengineering.stackexchange.com/questions/35063/how-do-you-update-your-production-codebase-database-schema-without-causing-downt#answers-header) 11 | - [High availability cluster (active-active/active-passive)](https://docs.oracle.com/cd/E17904_01/core.1111/e10106/intro.htm#ASHIA712) 12 | - [What is HTTPS](https://www.instantssl.com/http-vs-https) 13 | - [What is a firewall](https://www.webopedia.com/definitions/firewall/) 14 | - [Load Balancing Algorithms and Techniques](https://kemptechnologies.com/load-balancer/load-balancing-algorithms-techniques/) 15 | - [Active/Passive vs. Active/Active](https://kemptechnologies.com/fr/white-papers/unfog-confusion-active-passive-activeactive-load-balancing/) 16 | 17 | ## Tasks 18 | 19 |
20 | 0. Simple web stack
21 | image 22 | 29 |
30 | 31 |
32 | 1. Distributed web infrastructure
33 | image 34 |
35 | 36 |
37 | 2. Secured and monitored web infrastructure
38 | image 39 |
40 | 41 |
42 | 3. Scale up
43 | image 44 | 51 |
52 | -------------------------------------------------------------------------------- /0x0A-configuration_management/0-create_a_file.pp: -------------------------------------------------------------------------------- 1 | # Creates a file 2 | file { '/tmp/school': 3 | ensure => file, 4 | path => '/tmp/school', 5 | mode => '0744', 6 | owner => 'www-data', 7 | group => 'www-data', 8 | content => 'I love Puppet' 9 | } 10 | -------------------------------------------------------------------------------- /0x0A-configuration_management/1-install_a_package.pp: -------------------------------------------------------------------------------- 1 | # Install puppet-lint 2 | package { 'puppet-lint': 3 | ensure => '2.5.0', 4 | provider => 'gem' 5 | } 6 | -------------------------------------------------------------------------------- /0x0A-configuration_management/2-execute_a_command.pp: -------------------------------------------------------------------------------- 1 | # execute pkill command to kill bashscript file killmenow 2 | exec { 'pkill': 3 | command => 'pkill -9 -f killmenow', 4 | path => ['/usr/bin', '/usr/sbin', '/bin'] 5 | } 6 | -------------------------------------------------------------------------------- /0x0A-configuration_management/README.md: -------------------------------------------------------------------------------- 1 | # 0x0A. Configuration management 2 | 3 | ## Resource 4 | 5 | - [Intro to Configuration Management](https://www.digitalocean.com/community/tutorials/an-introduction-to-configuration-management) 6 | - [Puppet resource type: file](https://puppet.com/docs/puppet/5.5/types/file.html) (*Check "Resource types" for all manifest types in the left menu*) 7 | - [Puppet’s Declarative Language: Modeling Instead of Scripting](https://puppet.com/blog/puppets-declarative-language-modeling-instead-of-scripting/) 8 | - [Puppet lint](http://puppet-lint.com/) 9 | - [Puppet emacs mode](https://github.com/voxpupuli/puppet-mode) 10 | - [Puppet CookBook](https://www.puppetcookbook.com/) 11 | 12 | ## Installing `puppet` and `puppet-lint` 13 | 14 | ```sh 15 | # installing puppet and puppet-lint 16 | wget https://apt.puppet.com/puppet7-release-focal.deb && \ 17 | dpkg -i puppet7-release-focal.deb && \ 18 | apt-get update && \ 19 | apt-get install puppet-agent puppet-lint -y 20 | 21 | # confirming installation 22 | puppet -V 23 | puppet-lint -v 24 | 25 | # If you get an error saying puppet command not found, source the path 26 | source /etc/profile.d/puppet-agent.sh 27 | ``` 28 | 29 | ## Tasks 30 | 31 |
32 | 0. Create a file
33 | image 34 |
35 | 36 |
37 | 1. Install a package
38 | image 39 |
40 | 41 |
42 | 2. Execute a command
43 | image 44 |
45 | -------------------------------------------------------------------------------- /0x0A-configuration_management/killmenow: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | while [[ true ]] 3 | do 4 | sleep 2 5 | done 6 | -------------------------------------------------------------------------------- /0x0B-ssh/0-use_a_private_key: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Allows us to connect to my server using the private key with user ubuntu 3 | ssh -i ~/.ssh/school ubuntu@35.243.128.200 4 | -------------------------------------------------------------------------------- /0x0B-ssh/1-create_ssh_key_pair: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Creates an RSA SSH key pair 3 | ssh-keygen -f school -b 4096 -N betty 4 | -------------------------------------------------------------------------------- /0x0B-ssh/100-puppet_ssh_config.pp: -------------------------------------------------------------------------------- 1 | # using puppet to make changes to the default ssh config file 2 | # so that one can connect to a server without typing a password. 3 | 4 | include stdlib 5 | 6 | file_line { 'SSH Private Key': 7 | path => '/etc/ssh/ssh_config', 8 | line => ' IdentityFile ~/.ssh/school', 9 | match => '^[#]+[\s]*(?i)IdentityFile[\s]+~/.ssh/id_rsa$', 10 | replace => true, 11 | append_on_no_match => true 12 | } 13 | 14 | # Regex match explanation 15 | # 16 | # ^ beginning of the line 17 | # [#]* atleast one hash character 18 | # [\s]* zero or more white space characters 19 | # (?i)IdentityFile case insensitive "IdentityFile" 20 | # [\s]+ at least one whitespace character 21 | # ~/.ssh/id_rsa The ssh private key file path we want to replace 22 | # $ end of the line 23 | 24 | file_line { 'Deny Password Auth': 25 | path => '/etc/ssh/ssh_config', 26 | line => ' PasswordAuthentication no', 27 | match => '^[#]+[\s]*(?i)PasswordAuthentication[\s]+(yes|no)$', 28 | replace => true, 29 | append_on_no_match => true 30 | } 31 | 32 | # Regex match explanation 33 | # 34 | # ^ beginning of the line 35 | # [#]* atleast one hash character 36 | # [\s]* zero or more white space characters 37 | # (?i)PasswordAuthentication case insensitive "PasswordAuthentication" 38 | # [\s]+ at least one whitespace character 39 | # (yes|no) with the value "yes" or the value "no" 40 | # $ end of the line 41 | -------------------------------------------------------------------------------- /0x0B-ssh/2-ssh_config: -------------------------------------------------------------------------------- 1 | # SSH Config File 2 | # 3 | Host web-01 4 | Hostname 35.243.128.200 5 | User ubuntu 6 | PasswordAuthentication no 7 | IdentityFile ~/.ssh/school 8 | -------------------------------------------------------------------------------- /0x0B-ssh/README.md: -------------------------------------------------------------------------------- 1 | # 0x0B. SSH 2 | 3 | ## Resource 4 | 5 | - [What is a (physical) server - text](https://en.wikipedia.org/wiki/Server_%28computing%29#Hardware_requirement) 6 | - [What is a (physical) server - video](https://www.youtube.com/watch?v=B1ANfsDyjeA) 7 | - [SSH essentials](https://www.digitalocean.com/community/tutorials/ssh-essentials-working-with-ssh-servers-clients-and-keys) 8 | - [SSH Config File](https://www.ssh.com/academy/ssh/config) 9 | - [Public Key Authentication for SSH](https://www.ssh.com/academy/ssh/public-key-authentication) 10 | - [How Secure Shell Works](https://www.youtube.com/watch?v=ORcvSkgdA58) 11 | - [SSH Crash Course](https://www.youtube.com/watch?v=hQWRp-FdTpc) (*(Long, but highly informative. Watch this if configuring SSH is still confusing. It may be helpful to watch at x1.25 speed or above.*) 12 | 13 | ### For reference: 14 | 15 | - [Understanding the SSH Encryption and Connection Process](https://www.digitalocean.com/community/tutorials/understanding-the-ssh-encryption-and-connection-process) 16 | - [Secure Shell Wiki](https://en.wikipedia.org/wiki/Secure_Shell) 17 | - [IETF RFC 4251 (Description of the SSH Protocol)](https://www.ietf.org/rfc/rfc4251.txt) 18 | - [Internet Engineering Task Force](https://en.wikipedia.org/wiki/Internet_Engineering_Task_Force) 19 | - [Request for Comments (RFCs)](https://en.wikipedia.org/wiki/Request_for_Comments) 20 | 21 | ## Tasks 22 | 23 |
24 | 0. Use a private key
25 | image 26 |
27 | 28 |
29 | 1. Create an SSH key pair
30 | image 31 |
32 | 33 |
34 | 2. Client configuration file
35 | image 36 |
37 | 38 |
39 | 3. Let me in!
40 | image 41 |
42 | 43 |
44 | 4. Client configuration file (w/ Puppet)
45 | image
46 | 47 |
sudo puppet module install puppetlabs-stdlib
48 |
49 | 50 | -------------------------------------------------------------------------------- /0x0C-web_server/0-transfer_file: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Transfers a file from our client to a server 3 | # 4 | # variables 5 | path="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" 6 | filename=$(basename "$BASH_SOURCE") 7 | brown='\e[0;33m' 8 | reset='\033[0m' 9 | file="$1" 10 | ip="$2" 11 | user="$3" 12 | key="$4" 13 | 14 | if [ $# -eq 4 ]; then 15 | scp -i "$key" -o StrictHostKeyChecking=no "$path"/"$file" "$user"@"$ip":/home/"$user"/ 16 | else 17 | echo -e "Usage: ${brown}$filename PATH_TO_FILE IP USERNAME PATH_TO_SSH_KEY${reset}" 18 | fi 19 | -------------------------------------------------------------------------------- /0x0C-web_server/1-install_nginx_web_server: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Configures a new ubuntu machine by installing 3 | # Nginx where it should be listening on port 80 4 | # Serve a page that would return a Hello World string 5 | # 6 | # colors 7 | blue='\e[1;34m' 8 | brown='\e[0;33m' 9 | green='\e[1;32m' 10 | reset='\033[0m' 11 | 12 | echo -e "${blue}Updating and installing ${brown}Nginx${blue}.${reset}\n" 13 | sudo apt-get update -y -qq && \ 14 | sudo apt-get install nginx -y 15 | 16 | echo -e "\n${blue}Setting up some minor stuff.${reset}\n" 17 | 18 | # starting nginx service 19 | sudo service nginx start 20 | 21 | # allowing nginx on firewall 22 | sudo ufw allow 'Nginx HTTP' 23 | 24 | # Give the user ownership to website files for easy editing 25 | sudo chown -R "$USER":"$USER" /var/www/html 26 | sudo chmod -R 755 /var/www 27 | 28 | # Backup default index 29 | cp /var/www/html/index.nginx-debian.html /var/www/html/index.nginx-debian.html.bckp 30 | 31 | # Creating new index 32 | echo -e "Hello World!" | dd status=none of=/var/www/html/index.nginx-debian.html 33 | 34 | # Restarting nginx 35 | sudo service nginx restart 36 | 37 | echo -e "\n${green}Completed.${reset} ✅\n" 38 | -------------------------------------------------------------------------------- /0x0C-web_server/2-setup_a_domain_name: -------------------------------------------------------------------------------- 1 | th3gr00t.tech 2 | -------------------------------------------------------------------------------- /0x0C-web_server/3-redirection: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Configures a new ubuntu machine by installing 3 | # Nginx where it should be listening on port 80 4 | # Serve a page that would return a Hello World string 5 | # 6 | # colors 7 | blue='\e[1;34m' 8 | brown='\e[0;33m' 9 | green='\e[1;32m' 10 | reset='\033[0m' 11 | 12 | echo -e "${blue}Updating and installing ${brown}Nginx${blue}.${reset}\n" 13 | sudo apt-get update -y -qq && \ 14 | sudo apt-get install nginx -y 15 | 16 | echo -e "\n${blue}Setting up some minor stuff.${reset}\n" 17 | 18 | # starting nginx service 19 | sudo service nginx start 20 | 21 | # allowing nginx on firewall 22 | sudo ufw allow 'Nginx HTTP' 23 | 24 | # Give the user ownership to website files for easy editing 25 | sudo chown -R "$USER":"$USER" /var/www/html 26 | sudo chmod -R 755 /var/www 27 | 28 | # Backup default index 29 | cp /var/www/html/index.nginx-debian.html /var/www/html/index.nginx-debian.html.bckp 30 | 31 | # Creating new index 32 | echo -e "Hello World!" > /var/www/html/index.nginx-debian.html 33 | 34 | # Setting up /redirect_me to a youtube video 35 | sudo sed -i '24i\ rewrite ^/redirect_me https://www.youtube.com/watch?v=QH2-TGUlwu4 permanent;' /etc/nginx/sites-available/default 36 | 37 | # Restarting nginx 38 | sudo service nginx restart 39 | 40 | echo -e "\n${green}Completed.${reset} ✅\n" 41 | -------------------------------------------------------------------------------- /0x0C-web_server/4-not_found_page_404: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Configures a new ubuntu machine by installing 3 | # Nginx where it should be listening on port 80 4 | # Serve a page that would return a Hello World string 5 | # 6 | # colors 7 | blue='\e[1;34m' 8 | brown='\e[0;33m' 9 | green='\e[1;32m' 10 | reset='\033[0m' 11 | 12 | echo -e "${blue}Updating and installing ${brown}Nginx${blue}.${reset}\n" 13 | sudo apt-get update -y -qq && \ 14 | sudo apt-get install nginx -y 15 | 16 | echo -e "\n${blue}Setting up some minor stuff.${reset}\n" 17 | 18 | # starting nginx service 19 | sudo service nginx start 20 | 21 | # allowing nginx on firewall 22 | sudo ufw allow 'Nginx HTTP' 23 | 24 | # Give the user ownership to website files for easy editing 25 | sudo chown -R "$USER":"$USER" /var/www/html 26 | sudo chmod -R 755 /var/www 27 | 28 | # Backup default index 29 | cp /var/www/html/index.nginx-debian.html /var/www/html/index.nginx-debian.html.bckp 30 | 31 | # Creating new index 32 | echo -e "Hello World!" > /var/www/html/index.nginx-debian.html 33 | 34 | # Setting up /redirect_me to a youtube video 35 | sudo sed -i '24i\ rewrite ^/redirect_me https://www.youtube.com/watch?v=QH2-TGUlwu4 permanent;' /etc/nginx/sites-available/default 36 | 37 | # Set up a 404 page 38 | echo "Ceci n'est pas une page" >> /var/www/html/error_404.html 39 | sudo sed -i '25i\ error_page 404 /error_404.html;' /etc/nginx/sites-available/default 40 | 41 | # Restarting nginx 42 | sudo service nginx restart 43 | 44 | echo -e "\n${green}Completed.${reset} ✅\n" 45 | -------------------------------------------------------------------------------- /0x0C-web_server/7-puppet_install_nginx_web_server.pp: -------------------------------------------------------------------------------- 1 | # Setup New Ubuntu server with nginx 2 | 3 | exec { 'update system': 4 | command => '/usr/bin/apt-get update', 5 | } 6 | 7 | package { 'nginx': 8 | ensure => 'installed', 9 | require => Exec['update system'] 10 | } 11 | 12 | file {'/var/www/html/index.html': 13 | content => 'Hello World!' 14 | } 15 | 16 | exec {'redirect_me': 17 | command => 'sed -i "24i\ rewrite ^/redirect_me https://www.youtube.com/watch?v=QH2-TGUlwu4 permanent;" /etc/nginx/sites-available/default', 18 | provider => 'shell' 19 | } 20 | 21 | service {'nginx': 22 | ensure => running, 23 | require => Package['nginx'] 24 | } 25 | -------------------------------------------------------------------------------- /0x0C-web_server/README.md: -------------------------------------------------------------------------------- 1 | # 0x0C. Web server 2 | 3 |

4 | 5 |

6 | 7 | ## Resource 8 | 9 |
10 | Child Process
11 | image 12 |
13 | 14 | - [Background contenxt](https://www.youtube.com/watch?v=AZg4uJkEa-4) 15 | - [How the web works](https://developer.mozilla.org/en-US/docs/Learn/Getting_started_with_the_web/How_the_Web_works) 16 | - [Nginx](https://en.wikipedia.org/wiki/Nginx) 17 | - [How to Configure Nginx](https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-server-blocks-virtual-hosts-on-ubuntu-16-04) 18 | - [Root and sub domain](https://landingi.com/help/domains-vs-subdomains/) 19 | - [HTTP requests](https://www.tutorialspoint.com/http/http_methods.htm) 20 | - [HTTP redirection](https://moz.com/learn/seo/redirection) 21 | - [Not found HTTP response code](https://en.wikipedia.org/wiki/HTTP_404) 22 | - [Logs files on Linux](https://www.cyberciti.biz/faq/ubuntu-linux-gnome-system-log-viewer/) 23 | - [RFC 7231 (HTTP/1.1)](https://datatracker.ietf.org/doc/html/rfc7231) 24 | - [RFC 7540 (HTTP/2)](https://datatracker.ietf.org/doc/html/rfc7540) 25 | 26 | ## Tasks 27 | 28 |
29 | 0. Transfer a file to your server
30 | image 31 |
32 | 33 |
34 | 1. Install nginx web server
35 | image 36 | image 37 |
38 | 39 |
40 | 2. Setup a domain name
41 | image 42 |
43 | 44 |
45 | 3. Redirection
46 | image 47 |
48 | 49 |
50 | 4. Not found page 404
51 | image 52 |
53 | 54 |
55 | 5. Install Nginx web server (w/ Puppet)
56 | image 57 |
58 | -------------------------------------------------------------------------------- /0x0D-web_stack_debugging_0/0-give_me_a_page: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Start Apache so as to return a 3 | # page conatining Hello Holberton 4 | service apache2 start 5 | -------------------------------------------------------------------------------- /0x0D-web_stack_debugging_0/README.md: -------------------------------------------------------------------------------- 1 | # 0x0D. Web stack debugging #0 2 | 3 |

4 | 5 |

6 | 7 | ## Resource 8 | 9 | ### Concepts 10 | 11 |
12 | Network basics
13 | 21 |
22 | 23 |
24 | Docker
25 | 30 | 31 |
32 | Let's first pull a Docker image and run a container:
33 | image 34 |
35 | 36 | Note that `docker` command will pull the Ubuntu docker container image from the Internet and run it. I let you look at the meaning of the flags using the command `docker run --help`, the main idea is that it keeps the container up and running. 37 | 38 |
39 | To execute a command on the Docker container, use *docker exec*:
40 | image 41 |
42 | 43 |
44 | If you want to connect to your Docker container and use Bash, you need to use *docker exec -ti*:
45 | image 46 |
47 | 48 |
49 | If you want to stop a container, use *docker stop*:
50 | image 51 |
52 | 53 |
54 | 55 |
56 | Web stack debugging
57 | 66 | 67 |
68 | Test and verify your assumptions
69 | image 70 |
71 | 72 | 81 | 82 |
83 | 84 | ## Tasks 85 | 86 |
87 | 0. Give me a page!
88 | image 89 |
90 |
95 | -------------------------------------------------------------------------------- /0x0E-web_stack_debugging_1/0-nginx_likes_port_80: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # configures a server to listening on port 80 of all server's active IPv4 IPs 3 | 4 | sudo sed -i "s/8080/80/" /etc/nginx/sites-enabled/default 5 | sudo service nginx restart 6 | -------------------------------------------------------------------------------- /0x0E-web_stack_debugging_1/1-debugging_made_short: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # configures a server to listening on port 80 of all server's active IPv4 IPs 3 | sudo sed -i "s/8080/80/" /etc/nginx/sites-enabled/default 4 | sudo service nginx restart 5 | echo "" | sudo dd status=none of=/run/nginx.pid 6 | -------------------------------------------------------------------------------- /0x0E-web_stack_debugging_1/README.md: -------------------------------------------------------------------------------- 1 | # 0x0E. Web stack debugging #1 2 | 3 |

4 | 5 |

6 | 7 | ## Resource 8 | 9 | - [Resources from Web stack debugging #0](https://github.com/iAmG-r00t/alx-system_engineering-devops/tree/main/0x0D-web_stack_debugging_0#resource) 10 | 11 | 12 | ## Tasks 13 | 14 |
15 | 0. Nginx likes port 80
16 | image 17 |
18 | 19 |
20 | 1. Make it sweet and short
21 | image 22 |
23 | -------------------------------------------------------------------------------- /0x0F-load_balancer/0-custom_http_response_header: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # duplicate web-01 to web-02 3 | # these scripts are an upgrade from the web-server scripts... 4 | 5 | # uncomment to see the script run in action 6 | #set -x 7 | 8 | # colors 9 | blue='\e[1;34m' 10 | brown='\e[0;33m' 11 | green='\e[1;32m' 12 | reset='\033[0m' 13 | 14 | echo -e "${blue}Updating and doing some minor checks...${reset}\n" 15 | 16 | function install() { 17 | command -v "$1" &> /dev/null 18 | 19 | #shellcheck disable=SC2181 20 | if [ $? -ne 0 ]; then 21 | echo -e " Installing: ${brown}$1${reset}\n" 22 | sudo apt-get update -y -qq && \ 23 | sudo apt-get install -y "$1" -qq 24 | echo -e "\n" 25 | else 26 | echo -e " ${green}${1} is already installed.${reset}\n" 27 | fi 28 | } 29 | 30 | install nginx #install nginx 31 | 32 | echo -e "\n${blue}Setting up some minor stuff.${reset}\n" 33 | 34 | # allowing nginx on firewall 35 | sudo ufw allow 'Nginx HTTP' 36 | 37 | # Give the user ownership to website files for easy editing 38 | if [ -d "/var/www" ]; then 39 | sudo chown -R "$USER":"$USER" /var/www 40 | sudo chmod -R 755 /var/www 41 | else 42 | sudo mkdir -p /var/www 43 | sudo chown -R "$USER":"$USER" /var/www 44 | sudo chmod -R 755 /var/www 45 | fi 46 | 47 | # create directories if not present 48 | for dir in /var/www/{html,error}; do 49 | if ! [ -d "$dir" ]; then 50 | mkdir -p "$dir" 51 | fi 52 | done 53 | 54 | # creating new index 55 | echo "Hello World!" > /var/www/html/index.html 56 | 57 | # create new error page 58 | echo "Ceci n'est pas une page" > /var/www/html/error_404.html 59 | 60 | # backup default server config file 61 | sudo cp /etc/nginx/sites-enabled/default nginx-sites-enabled_default.backup 62 | 63 | server_config=\ 64 | "server { 65 | listen 80 default_server; 66 | listen [::]:80 default_server; 67 | root /var/www/html; 68 | index index.html index.htm index.nginx-debian.html 69 | server_name_; 70 | add_header X-Served-By \$hostname; 71 | location / { 72 | try_files \$uri \$uri/ =404; 73 | } 74 | if (\$request_filename ~ redirect_me){ 75 | rewrite ^ https://th3-gr00t.tk/ permanent; 76 | } 77 | error_page 404 /error_404.html; 78 | location = /error_404.html { 79 | internal; 80 | } 81 | }" 82 | 83 | #shellcheck disable=SC2154 84 | echo "$server_config" | sudo dd status=none of=/etc/nginx/sites-enabled/default 85 | 86 | if [ "$(pgrep -c nginx)" -le 0 ]; then 87 | sudo service nginx start 88 | else 89 | sudo service nginx restart 90 | fi 91 | -------------------------------------------------------------------------------- /0x0F-load_balancer/1-install_load_balancer: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # install load balancer 3 | 4 | # colors 5 | blue='\e[1;34m' 6 | brown='\e[0;33m' 7 | green='\e[1;32m' 8 | reset='\033[0m' 9 | 10 | echo -e "${blue}Updating and doing some minor checks...${reset}\n" 11 | 12 | function install() { 13 | command -v "$1" &> /dev/null 14 | 15 | #shellcheck disable=SC2181 16 | if [ $? -ne 0 ]; then 17 | echo -e " Installing: ${brown}$1${reset}\n" 18 | sudo apt-get update -y -qq && \ 19 | sudo apt-get install -y "$1" -qq 20 | echo -e "\n" 21 | else 22 | echo -e " ${green}${1} is already installed.${reset}\n" 23 | fi 24 | } 25 | 26 | install haproxy #install haproxy 27 | 28 | echo -e "\n${blue}Setting up some minor stuff.${reset}\n" 29 | 30 | # backup default server config file 31 | sudo cp /etc/haproxy/haproxy.cfg haproxy_default.backup 32 | 33 | server_config=\ 34 | " 35 | defaults 36 | mode http 37 | timeout client 15s 38 | timeout connect 10s 39 | timeout server 15s 40 | timeout http-request 10s 41 | 42 | frontend th3gr00t-tech-frontend 43 | bind *:80 44 | default_backend th3gr00t-tech-backend 45 | 46 | backend th3gr00t-tech-backend 47 | balance roundrobin 48 | server 453-web-01 35.243.128.200:80 check 49 | server 453-web-02 3.239.120.96:80 check 50 | " 51 | 52 | # shellcheck disable=SC2154 53 | echo "$server_config" | sudo dd status=none of=/etc/haproxy/haproxy.cfg 54 | 55 | # enable haproxy to be started by init script 56 | echo "ENABLED=1" | sudo dd status=none of=/etc/default/haproxy 57 | 58 | if [ "$(pgrep -c haproxy)" -le 0 ]; then 59 | sudo service haproxy start 60 | else 61 | sudo service haproxy restart 62 | fi 63 | -------------------------------------------------------------------------------- /0x0F-load_balancer/2-puppet_custom_http_response_header.pp: -------------------------------------------------------------------------------- 1 | # Setup New Ubuntu server with nginx 2 | # and add a custom HTTP header 3 | 4 | exec { 'update system': 5 | command => '/usr/bin/apt-get update', 6 | } 7 | 8 | package { 'nginx': 9 | ensure => 'installed', 10 | require => Exec['update system'] 11 | } 12 | 13 | file {'/var/www/html/index.html': 14 | content => 'Hello World!' 15 | } 16 | 17 | exec {'redirect_me': 18 | command => 'sed -i "24i\ rewrite ^/redirect_me https://th3-gr00t.tk/ permanent;" /etc/nginx/sites-available/default', 19 | provider => 'shell' 20 | } 21 | 22 | exec {'HTTP header': 23 | command => 'sed -i "25i\ add_header X-Served-By \$hostname;" /etc/nginx/sites-available/default', 24 | provider => 'shell' 25 | } 26 | 27 | service {'nginx': 28 | ensure => running, 29 | require => Package['nginx'] 30 | } 31 | -------------------------------------------------------------------------------- /0x0F-load_balancer/README.md: -------------------------------------------------------------------------------- 1 | # 0x0F. Load balancer 2 | 3 |

4 | 5 |

6 | 7 | ## Resource 8 | 9 |
10 | Load balancer
11 | 23 |
24 | 25 |
26 | Web stack debugging
27 | 36 | 37 |
38 | Test and verify your assumptions
39 | image 40 |
41 | 42 | 51 | 52 |
53 | 54 | - [Introduction to load-balancing and HAproxy](https://www.digitalocean.com/community/tutorials/an-introduction-to-haproxy-and-load-balancing-concepts) 55 | - [HAProxy Configuration Basics: Load Balance Your Servers](https://www.haproxy.com/blog/haproxy-configuration-basics-load-balance-your-servers/) 56 | - [The Four Essential Sections of an HAProxy Configuration](https://www.haproxy.com/blog/the-four-essential-sections-of-an-haproxy-configuration/) 57 | - [HTTP Header](https://www.techopedia.com/definition/27178/http-header) 58 | - [Debian/Ubuntu HAProxy packages](https://haproxy.debian.net/) 59 | 60 | ## Tasks 61 | 62 |
63 | 0. Double the number of webservers
64 | image 65 |
66 | 67 |
68 | 1. Install your load balancer
69 | image 70 |
71 | 72 |
73 | 2. Add a custom HTTP header with Puppet
74 | image 75 |
76 | -------------------------------------------------------------------------------- /0x10-https_ssl/0-world_wide_web: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays informtation about subdomains. 3 | 4 | # uncomment for debugging purposes. 5 | #set -x 6 | 7 | # for the checker to work please remove the colors. 8 | 9 | # colors 10 | blue='\e[1;34m' 11 | brown='\e[0;33m' 12 | reset='\033[0m' 13 | 14 | # variables & parameters 15 | subdomains=( "www" "lb-01" "web-01" "web-02" ) 16 | domain="$1" 17 | sub="$2" 18 | 19 | dig_cmd () { 20 | # func variables 21 | sub="$2" 22 | INFO="$(dig "$sub.$domain" | grep -A1 'ANSWER SECTION:' | awk 'NR==2')" 23 | IP=$(echo "$INFO" | awk '{print $5}') 24 | RECORD=$(echo "$INFO" | awk '{print $4}') 25 | 26 | echo -e "${brown}The subdomain ${blue}$sub${brown} is a ${blue}$RECORD${brown} record and points to ${blue}$IP${reset}" 27 | } 28 | 29 | if [ $# -eq 1 ]; then 30 | for subs in "${subdomains[@]}"; do 31 | dig_cmd "$domain" "$subs" 32 | done 33 | elif [ $# -eq 2 ]; then 34 | dig_cmd "$domain" "$sub" 35 | fi 36 | -------------------------------------------------------------------------------- /0x10-https_ssl/1-haproxy_ssl_termination: -------------------------------------------------------------------------------- 1 | global 2 | log /dev/log local0 3 | stats socket /run/haproxy/admin.sock mode 660 level admin 4 | 5 | defaults 6 | log global 7 | mode http 8 | option httplog 9 | timeout connect 10s 10 | timeout client 30s 11 | timeout server 30s 12 | 13 | frontend th3gr00t-tech-frontend 14 | bind *:80 15 | bind *:443 ssl crt /etc/haproxy/certs/th3gr00t.tech.pem 16 | http-request redirect scheme https unless { ssl_fc } 17 | http-request set-header X-Forwarded-Proto https 18 | default_backend th3gr00t-tech-backend 19 | 20 | backend th3gr00t-tech-backend 21 | balance roundrobin 22 | server 453-web-01 35.243.128.200:80 check 23 | server 453-web-02 3.239.120.96:80 check 24 | -------------------------------------------------------------------------------- /0x10-https_ssl/100-redirect_http_to_https: -------------------------------------------------------------------------------- 1 | global 2 | log /dev/log local0 3 | stats socket /run/haproxy/admin.sock mode 660 level admin 4 | 5 | defaults 6 | log global 7 | mode http 8 | option httplog 9 | timeout connect 10s 10 | timeout client 30s 11 | timeout server 30s 12 | 13 | frontend th3gr00t-tech-frontend 14 | bind *:80 15 | bind *:443 ssl crt /etc/haproxy/certs/th3gr00t.tech.pem 16 | http-request redirect scheme https code 301 unless { ssl_fc } 17 | http-request set-header X-Forwarded-Proto https 18 | default_backend th3gr00t-tech-backend 19 | 20 | backend th3gr00t-tech-backend 21 | balance roundrobin 22 | server 453-web-01 35.243.128.200:80 check 23 | server 453-web-02 3.239.120.96:80 check 24 | -------------------------------------------------------------------------------- /0x10-https_ssl/README.md: -------------------------------------------------------------------------------- 1 | # 0x10. HTTPS SSL 2 | 3 |

4 | 5 |

6 | 7 | ## Resource 8 | 9 | - [What is HTTPS?](https://www.instantssl.com/http-vs-https) 10 | - [What are the 2 main elements that SSL is providing](https://www.sslshopper.com/why-ssl-the-purpose-of-using-ssl-certificates.html) 11 | - [HAProxy SSL termination on Ubuntu16.04](https://devops.ionos.com/tutorials/install-and-configure-haproxy-load-balancer-on-ubuntu-1604/) 12 | - [SSL termination](https://en.wikipedia.org/wiki/TLS_termination_proxy) 13 | - [Bash function](https://tldp.org/LDP/abs/html/complexfunct.html) 14 | - [How to Secure HAProxy with Let's Encrypt on Ubuntu 14.04](https://www.digitalocean.com/community/tutorials/how-to-secure-haproxy-with-let-s-encrypt-on-ubuntu-14-04) 15 | - [HAProxy SSL Termination](https://www.haproxy.com/blog/haproxy-ssl-termination/) 16 | 17 | ## Tasks 18 | 19 |
20 | 0. World wide web
21 | image 22 |
23 | 24 |
25 | 1. HAproxy SSL termination
26 | image 27 |
28 | 29 |
30 | 2. No loophole in your website traffic
31 | image 32 |
33 | -------------------------------------------------------------------------------- /0x11-what_happens_when_your_type_google_com_in_your_browser_and_press_enter/0-blog_post: -------------------------------------------------------------------------------- 1 | https://gr00t.notion.site/What-Happens-846e145ce64f475f94f5a8bc713f171e 2 | -------------------------------------------------------------------------------- /0x11-what_happens_when_your_type_google_com_in_your_browser_and_press_enter/1-what_happen_when_diagram: -------------------------------------------------------------------------------- 1 | https://gr00t.notion.site/What-Happens-846e145ce64f475f94f5a8bc713f171e 2 | -------------------------------------------------------------------------------- /0x11-what_happens_when_your_type_google_com_in_your_browser_and_press_enter/README.md: -------------------------------------------------------------------------------- 1 | # 0x11. What happens when you type holbertonschool.com in your browser and press Enter 2 | 3 |

4 | 5 |

6 | 7 |
8 | Background Context 9 | 10 | - Being a Full-Stack Software Engineer means you’re comfortable interacting with any layer of the stack. 11 | - A way to easily assess this is to simply ask an engineer to explain how a software system works. They can have a general overview of the flow or can choose to dig deep in a certain area. 12 | - Let’s practice by exploring the infrastructure side (network, servers, security…) of the question. 13 | 14 |
15 | 16 |
17 | 0. What happens when...
18 | image 19 |
20 | 21 |
22 | 1. Everything's better with a pretty diagram
23 | 24 | image 25 | 26 | 27 | 28 | 29 |
30 | -------------------------------------------------------------------------------- /0x12-web_stack_debugging_2/0-iamsomeoneelse: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Runs whoami command under the user passed as an argument 3 | su "$1" -s /bin/bash -c 'whoami' 4 | -------------------------------------------------------------------------------- /0x12-web_stack_debugging_2/1-run_nginx_as_nginx: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Fixes the issue with the server 3 | chmod 644 /etc/nginx/nginx.conf 4 | sed -Ei 's/\s*#?\s*user .*/user nginx;/' /etc/nginx/nginx.conf 5 | sed -Ei 's/(listen (\[::\]:)?80) /\180 /' /etc/nginx/sites-enabled/default 6 | pkill apache2 7 | su nginx -s /bin/bash -c 'service nginx restart' 8 | -------------------------------------------------------------------------------- /0x12-web_stack_debugging_2/100-fix_in_7_lines_or_less: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Fixes the issue with the server 3 | chmod 644 /etc/nginx/nginx.conf 4 | sed -Ei 's/\s*#?\s*user .*/user nginx;/' /etc/nginx/nginx.conf 5 | sed -Ei 's/(listen (\[::\]:)?80) /\180 /' /etc/nginx/sites-enabled/default 6 | pkill apache2 7 | su nginx -s /bin/bash -c 'service nginx restart' 8 | -------------------------------------------------------------------------------- /0x12-web_stack_debugging_2/README.md: -------------------------------------------------------------------------------- 1 | # 0x12. Web stack debugging #2 2 | 3 |

4 | 5 |

6 | 7 | ## Tasks 8 | 9 |
10 | 0. Run software as another user
11 | power 12 | image 13 |
14 | 15 |
16 | 1. Run Nginx as Nginx
17 | image 18 |
19 | 20 |
21 | 2. 7 lines or less
22 | image 23 |
24 | -------------------------------------------------------------------------------- /0x13-firewall/0-block_all_incoming_traffic_but: -------------------------------------------------------------------------------- 1 | sudo apt-get install ufw -y 2 | sudo ufw default deny incoming 3 | sudo ufw default allow outgoing 4 | sudo ufw allow 22/tcp 5 | sudo ufw allow 443/tcp 6 | sudo ufw allow 80/tcp 7 | sudo ufw enable -y 8 | sudo ufw status 9 | -------------------------------------------------------------------------------- /0x13-firewall/100-port_forwarding: -------------------------------------------------------------------------------- 1 | # 2 | # /etc/ufw/before.rules 3 | # 4 | # rules.before 5 | # 6 | # Rules that should be run before the ufw command line added rules. Custom 7 | # rules should be added to one of these chains: 8 | # ufw-before-input 9 | # ufw-before-output 10 | # ufw-before-forward 11 | # 12 | 13 | # Don't delete these required lines, otherwise there will be errors 14 | *filter 15 | :ufw-before-input - [0:0] 16 | :ufw-before-output - [0:0] 17 | :ufw-before-forward - [0:0] 18 | :ufw-not-local - [0:0] 19 | # End required lines 20 | 21 | # Allow port forwarding from port 8080/TCP to port 80/TCP 22 | *nat 23 | :PREROUTING ACCEPT [0:0] 24 | -A PREROUTING -p tcp --dport 8080 -j REDIRECT --to-port 80 25 | COMMIT 26 | 27 | 28 | # allow all on loopback 29 | -A ufw-before-input -i lo -j ACCEPT 30 | -A ufw-before-output -o lo -j ACCEPT 31 | 32 | # quickly process packets for which we already have a connection 33 | -A ufw-before-input -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT 34 | -A ufw-before-output -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT 35 | -A ufw-before-forward -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT 36 | 37 | # drop INVALID packets (logs these in loglevel medium and higher) 38 | -A ufw-before-input -m conntrack --ctstate INVALID -j ufw-logging-deny 39 | -A ufw-before-input -m conntrack --ctstate INVALID -j DROP 40 | 41 | # ok icmp codes for INPUT 42 | -A ufw-before-input -p icmp --icmp-type destination-unreachable -j ACCEPT 43 | -A ufw-before-input -p icmp --icmp-type time-exceeded -j ACCEPT 44 | -A ufw-before-input -p icmp --icmp-type parameter-problem -j ACCEPT 45 | -A ufw-before-input -p icmp --icmp-type echo-request -j ACCEPT 46 | 47 | # ok icmp code for FORWARD 48 | -A ufw-before-forward -p icmp --icmp-type destination-unreachable -j ACCEPT 49 | -A ufw-before-forward -p icmp --icmp-type time-exceeded -j ACCEPT 50 | -A ufw-before-forward -p icmp --icmp-type parameter-problem -j ACCEPT 51 | -A ufw-before-forward -p icmp --icmp-type echo-request -j ACCEPT 52 | 53 | # allow dhcp client to work 54 | -A ufw-before-input -p udp --sport 67 --dport 68 -j ACCEPT 55 | 56 | # 57 | # ufw-not-local 58 | # 59 | -A ufw-before-input -j ufw-not-local 60 | 61 | # if LOCAL, RETURN 62 | -A ufw-not-local -m addrtype --dst-type LOCAL -j RETURN 63 | 64 | # if MULTICAST, RETURN 65 | -A ufw-not-local -m addrtype --dst-type MULTICAST -j RETURN 66 | 67 | # if BROADCAST, RETURN 68 | -A ufw-not-local -m addrtype --dst-type BROADCAST -j RETURN 69 | 70 | # all other non-local packets are dropped 71 | -A ufw-not-local -m limit --limit 3/min --limit-burst 10 -j ufw-logging-deny 72 | -A ufw-not-local -j DROP 73 | 74 | # allow MULTICAST mDNS for service discovery (be sure the MULTICAST line above 75 | # is uncommented) 76 | -A ufw-before-input -p udp -d 224.0.0.251 --dport 5353 -j ACCEPT 77 | 78 | # allow MULTICAST UPnP for service discovery (be sure the MULTICAST line above 79 | # is uncommented) 80 | -A ufw-before-input -p udp -d 239.255.255.250 --dport 1900 -j ACCEPT 81 | 82 | # don't delete the 'COMMIT' line or these rules won't be processed 83 | COMMIT 84 | -------------------------------------------------------------------------------- /0x13-firewall/README.md: -------------------------------------------------------------------------------- 1 | # 0x13. Firewall 2 | 3 |

4 | 5 |

6 | 7 | ### Your servers without a firewall... 8 | 9 |

10 | 11 |

12 | 13 | 14 | ## Resource 15 | 16 | - [What is a firewall](https://en.wikipedia.org/wiki/Firewall_%28computing%29) 17 | - [Port forwarding with iptables](https://www.cogini.com/blog/port-forwarding-with-iptables/) 18 | 19 | ## Tasks 20 | 21 |
22 | 0. Block all incoming traffic but
23 | image 24 |
25 | 26 |
27 | 1. Port forwarding
28 | 29 | Firewalls can not only filter requests, they can also forward them. 30 | 31 | Requirements: 32 | 33 | - Configure web-01 so that its firewall redirects port `8080/TCP` to port `80/TCP`. 34 | - Your answer file should be a copy of the `ufw` configuration file that you modified to make this happen 35 | Terminal in `web-01`: 36 | 37 | ```sh 38 | root@03-web-01:~# netstat -lpn 39 | Active Internet connections (only servers) 40 | Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name 41 | tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 2473/nginx 42 | tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 978/sshd 43 | tcp6 0 0 :::80 :::* LISTEN 2473/nginx 44 | tcp6 0 0 :::22 :::* LISTEN 978/sshd 45 | udp 0 0 0.0.0.0:68 0.0.0.0:* 594/dhclient 46 | udp 0 0 0.0.0.0:54432 0.0.0.0:* 594/dhclient 47 | udp6 0 0 :::32563 :::* 594/dhclient 48 | Active UNIX domain sockets (only servers) 49 | Proto RefCnt Flags Type State I-Node PID/Program name Path 50 | unix 2 [ ACC ] SEQPACKET LISTENING 7175 433/systemd-udevd /run/udev/control 51 | unix 2 [ ACC ] STREAM LISTENING 6505 1/init @/com/ubuntu/upstart 52 | unix 2 [ ACC ] STREAM LISTENING 8048 741/dbus-daemon /var/run/dbus/system_bus_socket 53 | unix 2 [ ACC ] STREAM LISTENING 8419 987/acpid /var/run/acpid.socket 54 | root@03-web-01:~# 55 | root@03-web-01:~# grep listen /etc/nginx/sites-enabled/default 56 | listen 80 default_server; 57 | listen [::]:80 default_server ipv6only=on; 58 | # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 59 | # listen 8000; 60 | # listen somename:8080; 61 | # listen 443; 62 | root@03-web-01:~# 63 | ``` 64 | 65 | - My web server `nginx` is only listening on port `80` 66 | - `netstat` shows that nothing is listening on `8080` 67 | Terminal in `web-02`: 68 | 69 | ```sh 70 | ubuntu@03-web-02:~$ curl -sI web-01.holberton.online:80 71 | HTTP/1.1 200 OK 72 | Server: nginx/1.4.6 (Ubuntu) 73 | Date: Tue, 07 Mar 2017 02:14:41 GMT 74 | Content-Type: text/html 75 | Content-Length: 612 76 | Last-Modified: Tue, 04 Mar 2014 11:46:45 GMT 77 | Connection: keep-alive 78 | ETag: "5315bd25-264" 79 | Accept-Ranges: bytes 80 | 81 | ubuntu@03-web-02:~$ curl -sI web-01.holberton.online:8080 82 | HTTP/1.1 200 OK 83 | Server: nginx/1.4.6 (Ubuntu) 84 | Date: Tue, 07 Mar 2017 02:14:43 GMT 85 | Content-Type: text/html 86 | Content-Length: 612 87 | Last-Modified: Tue, 04 Mar 2014 11:46:45 GMT 88 | Connection: keep-alive 89 | ETag: "5315bd25-264" 90 | Accept-Ranges: bytes 91 | 92 | ubuntu@03-web-02:~$ 93 | ``` 94 | I use curl to query `web-01.holberton.online`, and since my firewall is forwarding the ports, I get a `HTTP 200` response on port `80/TCP` and also on port `8080/TCP`. 95 | 96 |
97 | -------------------------------------------------------------------------------- /0x14-mysql/4-mysql_configuration_primary: -------------------------------------------------------------------------------- 1 | # 2 | # The MySQL Server configuration file. 3 | # 4 | 5 | [mysqld] 6 | pid-file = /var/run/mysqld/mysqld.pid 7 | socket = /var/run/mysqld/mysqld.sock 8 | datadir = /var/lib/mysql 9 | log-error = /var/log/mysql/error.log 10 | # By default we only accept connections from localhost 11 | bind-address = 0.0.0.0 12 | # Disabling symbolic-links is recommended to prevent assorted security risks 13 | symbolic-links=0 14 | # Distinguish servers in a replication setup 15 | server-id = 1 16 | # MySQL's Binary Log File 17 | log_bin = /var/log/mysql/mysql-bin.log 18 | # Database we want to replicate 19 | binlog_do_db = tyrell_corp 20 | -------------------------------------------------------------------------------- /0x14-mysql/4-mysql_configuration_replica: -------------------------------------------------------------------------------- 1 | # 2 | # The MySQL Server configuration file. 3 | # 4 | 5 | [mysqld] 6 | pid-file = /var/run/mysqld/mysqld.pid 7 | socket = /var/run/mysqld/mysqld.sock 8 | datadir = /var/lib/mysql 9 | log-error = /var/log/mysql/error.log 10 | # By default we only accept connections from localhost 11 | bind-address = 127.0.0.1 12 | # Disabling symbolic-links is recommended to prevent assorted security risks 13 | symbolic-links=0 14 | # Distinguish servers in a replication setup 15 | server-id = 2 16 | # MySQL's Binary Log File 17 | log_bin = /var/log/mysql/mysql-bin.log 18 | # Database we want to replicate 19 | binlog_do_db = tyrell_corp 20 | # Defines the location of the replica's relay log 21 | relay-log = /var/log/mysql/mysql-relay-bin.log 22 | -------------------------------------------------------------------------------- /0x14-mysql/5-mysql_backup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # backup and compress my databases 3 | 4 | # variables 5 | day=$(date +"%d") 6 | month=$(date +"%m") 7 | year=$(date +"%Y") 8 | file_name="$day-$month-$year.tar.gz" 9 | 10 | mysqldump --all-databases -u root --password="$1" > backup.sql 11 | tar -czvf "$file_name" backup.sql 12 | -------------------------------------------------------------------------------- /0x14-mysql/README.md: -------------------------------------------------------------------------------- 1 | # 0x14. MySQL 2 | 3 |

4 | 6 | 7 | ## Resource 8 | 9 | - [What is a database](https://searchdatamanagement.techtarget.com/definition/database) 10 | - [What is a database primary/replicate cluster](https://www.digitalocean.com/community/tutorials/how-to-choose-a-redundancy-plan-to-ensure-high-availability#sql-replication) 11 | - [MySQL primary/replicate setup](https://www.digitalocean.com/community/tutorials/how-to-set-up-replication-in-mysql) 12 | - [Build a robust database backup strategy](https://www.databasejournal.com/ms-sql/developing-a-sql-server-backup-strategy/) 13 | - [Privileges Provided by MySQL](https://dev.mysql.com/doc/refman/8.0/en/privileges-provided.html#priv_replication-client) (***Replication Client***) 14 | - [Creating User for Replication](https://dev.mysql.com/doc/refman/8.0/en/replication-howto-repuser.html) 15 | - [Setting up replicas](https://dev.mysql.com/doc/refman/5.7/en/replication-setup-replicas.html) (***MySQL 5.7.x***) 16 | 17 | ## Tasks 18 | 19 |

20 | 0. Install MySQL
21 | image 22 |
23 | 24 |
25 | 1. Let us in!
26 | 27 | image 28 | ```sh 29 | mysql> CREATE USER 'holberton_user'@'localhost' IDENTIFIED BY 'projectcorrection280hbtn'; 30 | mysql> GRANT REPLICATION CLIENT ON *.* to 'holberton_user'@'localhost'; 31 | mysql> FLUSH PRIVILEGES; 32 | ``` 33 | 34 |
35 | 36 |
37 | 2. If only you could see what I've seen with your eyes
38 | 39 | image 40 | ```sh 41 | mysql> CREATE DATABASE tyrell_corp; 42 | mysql> USE tyrell_corp; 43 | mysql> CREATE TABLE nexus6 (id INT, name VARCHAR(256)); 44 | mysql> INSERT INTO nexus6 (id, name) VALUES ('1', 'Leon'); 45 | mysql> GRANT SELECT ON tyrell_corp.nexus6 TO 'holberton_user'@'localhost'; 46 | ``` 47 | 48 |
49 | 50 |
51 | 3. Quite an experience to live in fear, isn't it?
52 | 53 | image 54 | ```sh 55 | msql> CREATE USER 'replica_user'@'%' IDENTIFIED BY 'password'; 56 | mysql> GRANT SELECT ON mysql.user TO 'holberton_user'@'localhost'; 57 | mysql> GRANT REPLICATION SLAVE ON *.* TO 'replica_user'@'%'; 58 | ``` 59 | 60 |
61 | 62 |
63 | 4. Setup a Primary-Replica infrastructure using MySQL
64 | 65 | 09e83e914f0d6865ce320a47f2f14837a5b190b6 66 | image 67 | image 68 | image 69 | 70 | + [MySQL primary configuration](./4-mysql_configuration_primary) 71 | + [MySQL replica configuration](./4-mysql_configuration_replica) 72 | 73 |
74 | 75 |
76 | 5. MySQL backup
77 | 78 | [![IMAGE ALT TEXT HERE](https://i.postimg.cc/3NtKg0gR/verizon.jpg)](https://www.youtube.com/watch?v=ANU-oSE5_hU) 79 | image 80 | 81 | ```sh 82 | ubuntu@03-web-01:~$ ls 83 | 5-mysql_backup 84 | ubuntu@03-web-01:~$ ./5-mysql_backup mydummypassword 85 | backup.sql 86 | ubuntu@03-web-01:~$ ls 87 | 01-03-2017.tar.gz 5-mysql_backup backup.sql 88 | ubuntu@03-web-01:~$ more backup.sql 89 | -- MySQL dump 10.13 Distrib 5.7.25, for debian-linux-gnu (x86_64) 90 | -- 91 | -- Host: localhost Database: 92 | -- ------------------------------------------------------ 93 | -- Server version 5.7.25-0ubuntu0.14.04.1 94 | 95 | /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; 96 | /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; 97 | /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; 98 | /*!40101 SET NAMES utf8 */; 99 | /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; 100 | /*!40103 SET TIME_ZONE='+00:00' */; 101 | /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; 102 | /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; 103 | /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; 104 | /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; 105 | 106 | -- 107 | -- Current Database: `tyrell_corp` 108 | -- 109 | 110 | CREATE DATABASE /*!32312 IF NOT EXISTS*/ `tyrell_corp` /*!40100 DEFAULT CHARACTER SET latin1 */; 111 | 112 | USE `tyrell_corp`; 113 | 114 | -- 115 | -- Table structure for table `nexus6` 116 | -- 117 | 118 | DROP TABLE IF EXISTS `nexus6`; 119 | /*!40101 SET @saved_cs_client = @@character_set_client */; 120 | /*!40101 SET character_set_client = utf8 */; 121 | CREATE TABLE `nexus6` ( 122 | `id` int(6) unsigned NOT NULL AUTO_INCREMENT, 123 | `firstname` varchar(30) NOT NULL, 124 | `lastname` varchar(30) NOT NULL, 125 | `email` varchar(50) DEFAULT NULL, 126 | `reg_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, 127 | PRIMARY KEY (`id`) 128 | ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1; 129 | /*!40101 SET character_set_client = @saved_cs_client */; 130 | ubuntu@03-web-01:~$ 131 | ubuntu@03-web-01:~$ file 01-03-2017.tar.gz 132 | 01-03-2017.tar.gz: gzip compressed data, from Unix, last modified: Wed Mar 1 23:38:09 2017 133 | ubuntu@03-web-01:~$ 134 | ``` 135 | 136 | + [Backup script](./5-mysql_backup) 137 | 138 |
139 | -------------------------------------------------------------------------------- /0x15-api/0-gather_data_from_an_API.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | '''A script that gathers employee name completed 3 | tasks and total number of tasks from an API 4 | ''' 5 | 6 | import re 7 | import requests 8 | import sys 9 | 10 | REST_API = "https://jsonplaceholder.typicode.com" 11 | 12 | if __name__ == '__main__': 13 | if len(sys.argv) > 1: 14 | if re.fullmatch(r'\d+', sys.argv[1]): 15 | id = int(sys.argv[1]) 16 | emp_req = requests.get('{}/users/{}'.format(REST_API, id)).json() 17 | task_req = requests.get('{}/todos'.format(REST_API)).json() 18 | emp_name = emp_req.get('name') 19 | tasks = list(filter(lambda x: x.get('userId') == id, task_req)) 20 | completed_tasks = list(filter(lambda x: x.get('completed'), tasks)) 21 | print( 22 | 'Employee {} is done with tasks({}/{}):'.format( 23 | emp_name, 24 | len(completed_tasks), 25 | len(tasks) 26 | ) 27 | ) 28 | if len(completed_tasks) > 0: 29 | for task in completed_tasks: 30 | print('\t {}'.format(task.get('title'))) 31 | -------------------------------------------------------------------------------- /0x15-api/README.md: -------------------------------------------------------------------------------- 1 | # 0x15. API 2 | 3 | ## Resource 4 | 5 | - [Friends don’t let friends program in shell script](https://www.turnkeylinux.org/blog/friends-dont-let-friends-program-shell-script) 6 | - [What is an API](https://www.webopedia.com/definitions/api/) 7 | - [What is an API? In English, please](https://www.freecodecamp.org/news/what-is-an-api-in-english-please-b880a3214a82/) 8 | - [What is a REST API](https://www.sitepoint.com/rest-api/) 9 | - [What are microservices](https://smartbear.com/solutions/microservices/) 10 | - [PEP8 Python style - having a clean code respecting style guide is really appreciated in the industry](https://www.python.org/dev/peps/pep-0008/) 11 | 12 | ## Tasks 13 | 14 |
15 | 0. Gather data from an API
16 | image 17 |
18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![img](https://assets.imaginablefutures.com/media/images/ALX_Logo.max-200x150.png) 2 | 3 | # 0x00 ALX System Engineering and DevOps 💥 4 | 5 | >Learning bash, scripting, networking and web infra right now, been wanting to get on this. It's going to be FUN !!. 6 | 7 | ## About 8 | 9 | - This repository consists of all the .Subject projects done with [ALX Africa](https://www.alxafrica.com/) Full stack Software Engineering course in partnership with [Holberton School](https://www.holbertonschool.com/) by [th3\_gr00t](https://th3-gr00t.tk/). 10 | 11 | --- 12 | 13 | - [0x00](./0x00-shell_basics) : Writing basic bash scripts that perform basic stuff. 14 | - [0x01](./0x01-shell_permissions) : Linux permissions. 15 | - [0x02](./0x02-shell_redirections) : Shell, I/O Redirections and filters. 16 | - [0x03](./0x03-shell_variables_expansions) : Shell, init files, variables and expansions. 17 | - [0x04](./0x04-loops_conditions_and_parsing) : Loops, conditions and parsing. 18 | - [0x05](./0x05-processes_and_signals) : Processes and signals. 19 | - [0x06](./0x06-regular_expressions) : Regular expression. 20 | - [0x07](./0x07-networking_basics) : Networking basics #0. 21 | - [0x08](./0x08-networking_basics_2) : Networking basics #1. 22 | - [0x09](./0x09-web_infrastructure_design) : Web infrastructure design. 23 | - [0x0A](./0x0A-configuration_management) : Configuration management. 24 | - [0x0B](./0x0B-ssh) : SSH. 25 | - [0x0C](./0x0C-web_server) : Web server. 26 | - [0x0D](./0x0D-web_stack_debugging_0) : Web stack debugging #0. 27 | - [0x0E](./0x0E-web_stack_debugging_1) : Web stack debugging #1. 28 | - [0x0F](./0x0F-load_balancer) : Load balancer. 29 | - [0x10](./0x10-https_ssl) : HTTPS SSL. 30 | - [0x11](./0x11-what_happens_when_your_type_google_com_in_your_browser_and_press_enter) : What happens when you type holbertonschool.com in your browser and press Enter. 31 | - [0x12](./0x12-web_stack_debugging_2) : Web stack debugging #2. 32 | - [0x13](./0x13-firewall) : Firewall. 33 | - [0x14](./0x14-mysql) : MySQL. 34 | - [0x15](./0x15-api) : API. 35 | - [Attack is the best defense.](./attack_is_the_best_defense) 36 | -------------------------------------------------------------------------------- /attack_is_the_best_defense/0-sniffing: -------------------------------------------------------------------------------- 1 | mypassword9898! 2 | -------------------------------------------------------------------------------- /attack_is_the_best_defense/1-dictionary_attack: -------------------------------------------------------------------------------- 1 | password123 2 | -------------------------------------------------------------------------------- /attack_is_the_best_defense/README.md: -------------------------------------------------------------------------------- 1 | # Attack is the best defense 2 | 3 | ## Resource 4 | 5 | - [Network sniffing](https://www.lifewire.com/definition-of-sniffer-817996) 6 | - [ARP spoofing](https://www.veracode.com/security/arp-spoofing) 7 | - [Connect to SendGrid’s SMTP relay using telnet](https://docs.sendgrid.com/ui/account-and-settings/troubleshooting-delays-and-latency) 8 | - [What is Docker and why is it popular?](https://www.zdnet.com/article/what-is-docker-and-why-is-it-so-darn-popular/) 9 | - [Dictionary attack](https://en.wikipedia.org/wiki/Dictionary_attack) 10 | 11 | ## Tasks 12 | 13 |
14 | 0. ARP spoofing and sniffing unencrypted traffic
15 | 16 | image 17 | 18 | ```sh 19 | sylvain@ubuntu$ telnet smtp.sendgrid.net 587 20 | Trying 167.89.121.145... 21 | Connected to smtp.sendgrid.net. 22 | Escape character is '^]'. 23 | 220 SG ESMTP service ready at ismtpd0013p1las1.sendgrid.net 24 | EHLO ismtpd0013p1las1.sendgrid.net 25 | 250-smtp.sendgrid.net 26 | 250-8BITMIME 27 | 250-PIPELINING 28 | 250-SIZE 31457280 29 | 250-STARTTLS 30 | 250-AUTH PLAIN LOGIN 31 | 250 AUTH=PLAIN LOGIN 32 | auth login 33 | 334 VXNlcm5hbWU6 34 | VGhpcyBpcyBteSBsb2dpbg== 35 | 334 UGFzc3dvcmQ6 36 | WW91IHJlYWxseSB0aG91Z2h0IEkgd291bGQgbGV0IG15IHBhc3N3b3JkIGhlcmU/ISA6RA== 37 | 235 Authentication successful 38 | mail from: sylvain@kalache.fr 39 | 250 Sender address accepted 40 | rcpt to: julien@google.com 41 | 250 Recipient address accepted 42 | data 43 | 354 Continue 44 | To: Julien 45 | From: Sylvain 46 | Subject: Hello from the insecure world 47 | 48 | I am sending you this email from a Terminal. 49 | . 50 | 250 Ok: queued as Aq1zhMM3QYeEprixUiFYNg 51 | quit 52 | 221 See you later 53 | Connection closed by foreign host. 54 | sylvain@ubuntu$ 55 | ``` 56 | 57 | image 58 | 59 | ```sh 60 | # Run this when there is no other process running, 61 | # ...tried to find a way to specifically filter the specif process but 62 | # ...the best option was to run it in a virtual enviroment 63 | # ...also base64 should be your best friend 64 | sudo tcpdump -A -l 65 | ``` 66 | 67 | - [user\_authenticating\_into\_server](./user_authenticating_into_server) binary script file. 68 | 69 |
70 | 71 |
72 | 1. Dictionary attack
73 | 74 | image 75 | 76 | - [Wordlist](https://github.com/brannondorsey/naive-hashcat/releases/download/data/rockyou.txt) **Rockyou.txt** 77 | 78 | ```sh 79 | # command 80 | hydra -V -s 2222 -l sylvain -P rockyou.txt 127.0.0.1 ssh -t 64 81 | ``` 82 | 83 |
84 | -------------------------------------------------------------------------------- /attack_is_the_best_defense/user_authenticating_into_server: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iAmG-r00t/alx-system_engineering-devops/094b0b695ae36afe9cab41023ee0ce8573843ad4/attack_is_the_best_defense/user_authenticating_into_server --------------------------------------------------------------------------------