├── .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 └── commandlog ├── 0x11-what_happens_when_your_type_google_com_in_your_browser_and_press_enter └── 0-blog_post ├── 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 ├── install_log ├── replication ├── setup.sql ├── setup_master └── setup_slave ├── 0x15-api ├── 0-gather_data_from_an_API.py ├── 1-export_to_CSV.py ├── 2-export_to_JSON.py ├── 3-dictionary_of_list_of_dictionaries.py ├── AUTHORS └── README.md ├── 0x16-api_advanced ├── 0-subs.py ├── 1-top_ten.py ├── 100-count.py ├── 2-recurse.py └── README.md ├── 0x17-web_stack_debugging_3 ├── 0-strace_is_your_friend.pp └── README.md ├── 0x18-webstack_monitoring └── README.md ├── 0x1A-application_server ├── 2-app_server-nginx_config ├── 3-app_server-nginx_config ├── 4-app_server-nginx_config ├── 4-reload_gunicorn_no_downtime ├── 5-app_server-nginx_config ├── README.md ├── app-server └── gunicorn.service ├── 0x1B-web_stack_debugging_4 ├── 0-the_sky_is_the_limit_not.pp ├── 1-user_limit.pp └── README.md ├── README.md ├── attack_is_the_best_defense ├── 0-sniffing ├── 1-dictionary_attack ├── README.md └── user_authenticating_into_server └── command_line_for_the_win └── README.md /.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 AAAAB3NzaC1yc2EAAAADAQABAAABgQC9KA+qmAaobVygBQtT5otcYzBguKsKNyLUQyeIXMihkMetZksCrDLPTwUek//OG9jftxEvz9vG1AHIBraRadrCd3P6rwCsHzLQCv05/+RfcHQpsRzc2HlsNXu9qKINZ7oc/3DMdf9OiBTmjPYexvrwg32iHMFCEWr1Hcmv4++QR6ZJ9ursn3WeaObzxWUpwlBRiFUMa0oluN83le91HjnWZ7XO9oxfIWFNoPF38BbMVfoOIg4E3PRD/Z4DcPa0QwGG1SHx+inkKqCk9sRXW3D6MPEBDb15e1Yd5WhSaou9fDm9TflqCZpGG2ysoQfI1HgYf8AgoEGy2brgETTJHINwCLNUue72LAol3sTNbJg21FYabQPaVwVdzVbkeJ/Z3D0fD0IctlxonT7FU/NvMd6xQ78R95VQe5KV7EbPFCdWpAYHNjZuIVQ5dQC024O2avuuiHR5qLxVceNMOX80D2/t83FHWQV7OK/4LQOxIVbTtblz/RROLUubv7v3Aw6b/Sk= root@36c160f50a12 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/hardope/alx-system_engineering-devops/dd88b5396fa91e3e23dd881a45175ae3522506ae/0x09-web_infrastructure_design/0-simple_web_stack.jpg -------------------------------------------------------------------------------- /0x09-web_infrastructure_design/0-simple_web_stack.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/alx-system_engineering-devops/dd88b5396fa91e3e23dd881a45175ae3522506ae/0x09-web_infrastructure_design/0-simple_web_stack.pdf -------------------------------------------------------------------------------- /0x09-web_infrastructure_design/1-distributed_web_infrastructure.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/alx-system_engineering-devops/dd88b5396fa91e3e23dd881a45175ae3522506ae/0x09-web_infrastructure_design/1-distributed_web_infrastructure.jpg -------------------------------------------------------------------------------- /0x09-web_infrastructure_design/1-distributed_web_infrastructure.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/alx-system_engineering-devops/dd88b5396fa91e3e23dd881a45175ae3522506ae/0x09-web_infrastructure_design/1-distributed_web_infrastructure.pdf -------------------------------------------------------------------------------- /0x09-web_infrastructure_design/2-secured_and_monitored_web_infrastructure.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/alx-system_engineering-devops/dd88b5396fa91e3e23dd881a45175ae3522506ae/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/hardope/alx-system_engineering-devops/dd88b5396fa91e3e23dd881a45175ae3522506ae/0x09-web_infrastructure_design/2-secured_and_monitored_web_infrastructure.pdf -------------------------------------------------------------------------------- /0x09-web_infrastructure_design/3-scale_up.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/alx-system_engineering-devops/dd88b5396fa91e3e23dd881a45175ae3522506ae/0x09-web_infrastructure_design/3-scale_up.jpg -------------------------------------------------------------------------------- /0x09-web_infrastructure_design/3-scale_up.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/alx-system_engineering-devops/dd88b5396fa91e3e23dd881a45175ae3522506ae/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 flask 2 | package { 'flask': 3 | ensure => '2.1.0', 4 | provider => 'pip3' 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/id_rsa ubuntu@18.235.249.46 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 | if [ $# -lt 4 ] 6 | then 7 | echo "Usage: 0-transfer_file PATH_TO_FILE IP USERNAME PATH_TO_SSH_KEY" 8 | else 9 | scp -o StrictHostKeyChecking=no -i "$4" "$1" "$3@$2":~ 10 | fi 11 | -------------------------------------------------------------------------------- /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 | 7 | echo -e "Updating and installing Nginx.\n" 8 | sudo apt-get update -y -qq && \ 9 | sudo apt-get install nginx -y 10 | 11 | echo -e "\nSetting up some minor stuff.\n" 12 | 13 | # starting nginx service 14 | sudo service nginx start 15 | 16 | # allowing nginx on firewall 17 | sudo ufw allow 'Nginx HTTP' 18 | 19 | # Give the user ownership to website files for easy editing 20 | sudo chown -R "$USER":"$USER" /var/www/html 21 | sudo chmod -R 755 /var/www 22 | 23 | # Backup default index 24 | cp /var/www/html/index.nginx-debian.html /var/www/html/index.nginx-debian.html.bckp 25 | 26 | # Creating new index 27 | echo -e "Hello World!" | dd status=none of=/var/www/html/index.nginx-debian.html 28 | 29 | # Restarting nginx 30 | sudo service nginx restart 31 | 32 | echo -e "\nCompleted. ✅\n" 33 | -------------------------------------------------------------------------------- /0x0C-web_server/2-setup_a_domain_name: -------------------------------------------------------------------------------- 1 | clickviral.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 | 7 | 8 | echo -e "Updating and installing Nginx.\n" 9 | sudo apt-get update -y -qq && \ 10 | sudo apt-get install nginx -y 11 | 12 | echo -e "\nSetting up some minor stuff.\n" 13 | 14 | # starting nginx service 15 | sudo service nginx start 16 | 17 | # allowing nginx on firewall 18 | sudo ufw allow 'Nginx HTTP' 19 | 20 | # Give the user ownership to website files for easy editing 21 | sudo chown -R "$USER":"$USER" /var/www/html 22 | sudo chmod -R 755 /var/www 23 | 24 | # Backup default index 25 | cp /var/www/html/index.nginx-debian.html /var/www/html/index.nginx-debian.html.bckp 26 | 27 | # Creating new index 28 | echo -e "Hello World!" > /var/www/html/index.nginx-debian.html 29 | 30 | # Setting up /redirect_me to a youtube video 31 | sudo sed -i '24i\ rewrite ^/redirect_me https://www.youtube.com/watch?v=QH2-TGUlwu4 permanent;' /etc/nginx/sites-available/default 32 | 33 | # Restarting nginx 34 | sudo service nginx restart 35 | 36 | echo -e "\nCompleted.\n" 37 | -------------------------------------------------------------------------------- /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 | 7 | echo -e "Updating and installing Nginx.\n" 8 | sudo apt-get update -y -qq && \ 9 | sudo apt-get install nginx -y 10 | 11 | echo -e "\nSetting up some minor stuff.\n" 12 | 13 | # starting nginx service 14 | sudo service nginx start 15 | 16 | # allowing nginx on firewall 17 | sudo ufw allow 'Nginx HTTP' 18 | 19 | # Give the user ownership to website files for easy editing 20 | sudo chown -R "$USER":"$USER" /var/www/html 21 | sudo chmod -R 755 /var/www 22 | 23 | # Backup default index 24 | cp /var/www/html/index.nginx-debian.html /var/www/html/index.nginx-debian.html.bckp 25 | 26 | # Creating new index 27 | echo -e "Hello World!" > /var/www/html/index.nginx-debian.html 28 | 29 | # Setting up /redirect_me to a youtube video 30 | sudo sed -i '24i\ rewrite ^/redirect_me https://www.youtube.com/watch?v=QH2-TGUlwu4 permanent;' /etc/nginx/sites-available/default 31 | 32 | # Set up a 404 page 33 | echo "Ceci n'est pas une page" >> /var/www/html/error_404.html 34 | sudo sed -i '25i\ error_page 404 /error_404.html;' /etc/nginx/sites-available/default 35 | 36 | # Restarting nginx 37 | sudo service nginx restart 38 | 39 | echo -e "\nCompleted.\n" 40 | -------------------------------------------------------------------------------- /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 servers active IPv4 IPs 3 | 4 | sudo ln -sf /etc/nginx/sites-available/default /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 servers active IPv4 IPs 3 | 4 | sudo sed -i "s/8080/80/" /etc/nginx/sites-enabled/default 5 | sudo service nginx restart 6 | echo "" | sudo dd status=none of=/run/nginx.pid 7 | -------------------------------------------------------------------------------- /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 | echo -e "Updating and doing some minor checks...\n" 9 | 10 | function install() { 11 | command -v "$1" &> /dev/null 12 | 13 | #shellcheck disable=SC2181 14 | if [ $? -ne 0 ]; then 15 | echo -e " Installing: $1$\n" 16 | sudo apt-get update -y -qq && \ 17 | sudo apt-get install -y "$1" -qq 18 | echo -e "\n" 19 | else 20 | echo -e " ${1} is already installed.\n" 21 | fi 22 | } 23 | 24 | install nginx #install nginx 25 | 26 | echo -e "\nSetting up some minor stuff.\n" 27 | 28 | # allowing nginx on firewall 29 | sudo ufw allow 'Nginx HTTP' 30 | 31 | # Give the user ownership to website files for easy editing 32 | if [ -d "/var/www" ]; then 33 | sudo chown -R "$USER":"$USER" /var/www 34 | sudo chmod -R 755 /var/www 35 | else 36 | sudo mkdir -p /var/www 37 | sudo chown -R "$USER":"$USER" /var/www 38 | sudo chmod -R 755 /var/www 39 | fi 40 | 41 | # create directories if not present 42 | for dir in /var/www/{html,error}; do 43 | if ! [ -d "$dir" ]; then 44 | mkdir -p "$dir" 45 | fi 46 | done 47 | 48 | # creating new index 49 | echo "Hello World!" > /var/www/html/index.html 50 | 51 | # create new error page 52 | echo "Ceci n'est pas une page" > /var/www/html/error_404.html 53 | 54 | # backup default server config file 55 | sudo cp /etc/nginx/sites-enabled/default nginx-sites-enabled_default.backup 56 | 57 | server_config=\ 58 | "server { 59 | listen 80 default_server; 60 | listen [::]:80 default_server; 61 | root /var/www/html; 62 | index index.html index.htm index.nginx-debian.html 63 | server_name_; 64 | add_header X-Served-By \$hostname; 65 | location / { 66 | try_files \$uri \$uri/ =404; 67 | } 68 | if (\$request_filename ~ redirect_me){ 69 | rewrite ^ https://th3-gr00t.tk/ permanent; 70 | } 71 | error_page 404 /error_404.html; 72 | location = /error_404.html { 73 | internal; 74 | } 75 | }" 76 | 77 | #shellcheck disable=SC2154 78 | echo "$server_config" | sudo dd status=none of=/etc/nginx/sites-enabled/default 79 | 80 | if [ "$(pgrep -c nginx)" -le 0 ]; then 81 | sudo service nginx start 82 | else 83 | sudo service nginx restart 84 | fi 85 | -------------------------------------------------------------------------------- /0x0F-load_balancer/1-install_load_balancer: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # install load balancer 3 | 4 | 5 | echo -e "Updating and doing some minor checks...\n" 6 | 7 | function install() { 8 | command -v "$1" &> /dev/null 9 | 10 | #shellcheck disable=SC2181 11 | if [ $? -ne 0 ]; then 12 | echo -e " Installing: $1\n" 13 | sudo apt-get update -y -qq && \ 14 | sudo apt-get install -y "$1" -qq 15 | echo -e "\n" 16 | else 17 | echo -e " ${1} is already installed.\n" 18 | fi 19 | } 20 | 21 | install haproxy #install haproxy 22 | 23 | echo -e "\nSetting up some minor stuff.\n" 24 | 25 | # backup default server config file 26 | sudo cp /etc/haproxy/haproxy.cfg haproxy_default.backup 27 | 28 | server_config=\ 29 | " 30 | defaults 31 | mode http 32 | timeout client 15s 33 | timeout connect 10s 34 | timeout server 15s 35 | timeout http-request 10s 36 | 37 | frontend clickviral-tech-frontend 38 | bind *:80 39 | default_backend clickviral-tech-backend 40 | 41 | backend clickviral-tech-backend 42 | balance roundrobin 43 | server 151666-web-01 100.25.190.21:80 check 44 | server 151666-web-02 54.160.77.90:80 check 45 | " 46 | 47 | # shellcheck disable=SC2154 48 | echo "$server_config" | sudo dd status=none of=/etc/haproxy/haproxy.cfg 49 | 50 | # enable haproxy to be started by init script 51 | echo "ENABLED=1" | sudo dd status=none of=/etc/default/haproxy 52 | 53 | echo "configured - Roundrobin On web-01 & web-02" 54 | 55 | if [ "$(pgrep -c haproxy)" -le 0 ]; then 56 | sudo service haproxy start 57 | else 58 | sudo service haproxy restart 59 | fi 60 | 61 | echo -e "web-01 web-02" 62 | echo "web-01" 63 | echo "web-02" 64 | -------------------------------------------------------------------------------- /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 | # print domains and subdomains 3 | 4 | print_domain_subdomain () { 5 | dig "$1" | grep -A1 'ANSWER SECTION:' | sed -r "s/$1./$2/g" | awk -F" " ' NR==2 { print "The subdomain " $1 " is a " $4 " record and points to " $5 }' 6 | } 7 | 8 | if [ "$#" -eq 2 ] 9 | then 10 | print_domain_subdomain "$2.$1" "$2" 11 | else 12 | print_domain_subdomain "www.$1" "www" 13 | print_domain_subdomain "lb-01.$1" "lb-01" 14 | print_domain_subdomain "web-01.$1" "web-01" 15 | print_domain_subdomain "web-02.$1" "web-02" 16 | fi -------------------------------------------------------------------------------- /0x10-https_ssl/1-haproxy_ssl_termination: -------------------------------------------------------------------------------- 1 | global 2 | log /dev/log local0 3 | log /dev/log local1 notice 4 | chroot /var/lib/haproxy 5 | stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners 6 | stats timeout 30s 7 | user haproxy 8 | group haproxy 9 | daemon 10 | 11 | # Default SSL material locations 12 | ca-base /etc/ssl/certs 13 | crt-base /etc/ssl/private 14 | 15 | # See: https://ssl-config.mozilla.org/#server=haproxy&server-version=2.0.3&config=intermediate 16 | ssl-default-bind-ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-S> 17 | ssl-default-bind-ciphersuites TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256 18 | ssl-default-bind-options ssl-min-ver TLSv1.2 no-tls-tickets 19 | 20 | defaults 21 | log global 22 | mode http 23 | option httplog 24 | option dontlognull 25 | timeout connect 5000 26 | timeout client 50000 27 | timeout server 50000 28 | errorfile 400 /etc/haproxy/errors/400.http 29 | errorfile 403 /etc/haproxy/errors/403.http 30 | errorfile 408 /etc/haproxy/errors/408.http 31 | errorfile 500 /etc/haproxy/errors/500.http 32 | errorfile 502 /etc/haproxy/errors/502.http 33 | errorfile 503 /etc/haproxy/errors/503.http 34 | errorfile 504 /etc/haproxy/errors/504.http 35 | 36 | frontend clickviral-frontend 37 | bind *:80 38 | mode http 39 | http-request redirect scheme https code 301 unless { ssl_fc } 40 | http-request set-header X_Forwarded-Proto http 41 | default_backend clickviral-backend 42 | 43 | frontend clickviral-frontend-https 44 | bind *:443 ssl crt /etc/haproxy/certs/clickviral.tech.pem 45 | http-request set-header X-Forwarded-Proto https 46 | default_backend clickviral-backend 47 | 48 | backend clickviral-backend 49 | balance roundrobin 50 | server 151666-web-01 100.25.190.21:80 check 51 | server 151666-web-02 54.160.77.90:80 check 52 | -------------------------------------------------------------------------------- /0x10-https_ssl/100-redirect_http_to_https: -------------------------------------------------------------------------------- 1 | global 2 | log /dev/log local0 3 | log /dev/log local1 notice 4 | chroot /var/lib/haproxy 5 | stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners 6 | stats timeout 30s 7 | user haproxy 8 | group haproxy 9 | daemon 10 | 11 | # Default SSL material locations 12 | ca-base /etc/ssl/certs 13 | crt-base /etc/ssl/private 14 | 15 | # See: https://ssl-config.mozilla.org/#server=haproxy&server-version=2.0.3&config=intermediate 16 | ssl-default-bind-ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-S> 17 | ssl-default-bind-ciphersuites TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256 18 | ssl-default-bind-options ssl-min-ver TLSv1.2 no-tls-tickets 19 | 20 | defaults 21 | log global 22 | mode http 23 | option httplog 24 | option dontlognull 25 | timeout connect 5000 26 | timeout client 50000 27 | timeout server 50000 28 | errorfile 400 /etc/haproxy/errors/400.http 29 | errorfile 403 /etc/haproxy/errors/403.http 30 | errorfile 408 /etc/haproxy/errors/408.http 31 | errorfile 500 /etc/haproxy/errors/500.http 32 | errorfile 502 /etc/haproxy/errors/502.http 33 | errorfile 503 /etc/haproxy/errors/503.http 34 | errorfile 504 /etc/haproxy/errors/504.http 35 | 36 | frontend clickviral-frontend 37 | bind *:80 38 | mode http 39 | http-request redirect scheme https code 301 unless { ssl_fc } 40 | http-request set-header X_Forwarded-Proto http 41 | default_backend clickviral-backend 42 | 43 | frontend clickviral-frontend-https 44 | bind *:443 ssl crt /etc/haproxy/certs/clickviral.tech.pem 45 | http-request set-header X-Forwarded-Proto https 46 | default_backend clickviral-backend 47 | 48 | backend clickviral-backend 49 | balance roundrobin 50 | server 151666-web-01 100.25.190.21:80 check 51 | server 151666-web-02 54.160.77.90:80 check 52 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /0x10-https_ssl/commandlog: -------------------------------------------------------------------------------- 1 | sudo apt update 2 | sudo apt install snapd 3 | sudo apt-get remove certbot 4 | sudo apt-get install certbot 5 | sudo certbot certonly --standalone --preferred-challenges http --http-01-port 80 -d example.com -d www.example.com 6 | sudo ls /etc/letsencrypt/live/your_domain_name 7 | sudo mkdir -p /etc/haproxy/certs 8 | DOMAIN='example.com' sudo -E bash -c 'cat /etc/letsencrypt/live/$DOMAIN/fullchain.pem /etc/letsencrypt/live/$DOMAIN/privkey.pem > /etc/haproxy/certs/$DOMAIN.pem' 9 | sudo chmod -R go-rwx /etc/haproxy/certs 10 | sudo nano /etc/haproxy/haproxy.cfg 11 | -------------------------------------------------------------------------------- /0x11-what_happens_when_your_type_google_com_in_your_browser_and_press_enter/0-blog_post: -------------------------------------------------------------------------------- 1 | https://www.linkedin.com/pulse/what-happens-when-you-type-url-browser-press-enter-opeoluwa-adeyeri -------------------------------------------------------------------------------- /0x12-web_stack_debugging_2/0-iamsomeoneelse: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Runs whoami command as the user provided in argument 3 | sudo -u "$1" whoami 4 | -------------------------------------------------------------------------------- /0x12-web_stack_debugging_2/1-run_nginx_as_nginx: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Fixes server bug 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 | # restart 8 | su nginx -s /bin/bash -c 'service nginx restart' 9 | -------------------------------------------------------------------------------- /0x12-web_stack_debugging_2/100-fix_in_7_lines_or_less: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Fixes server bug 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 | echo -e "Updating\n" 2 | 3 | sudo apt-get update 4 | 5 | echo -e "Installing UFW\n" 6 | 7 | sudo apt-get install -y ufw 8 | 9 | echo -e "configuring UFW...\n" 10 | 11 | # Allow Outgoing and Deny Incoming 12 | sudo ufw default deny incoming 13 | sudo ufw default allow outgoing 14 | 15 | # Allow ports 16 | sudo ufw allow 22 17 | sudo ufw allow 80 18 | sudo ufw allow 443 19 | 20 | # Enable Fire Wall 21 | sudo ufw enable 22 | 23 | echo -e "Process Completed.\n" 24 | -------------------------------------------------------------------------------- /0x13-firewall/100-port_forwarding: -------------------------------------------------------------------------------- 1 | # 2 | # rules.before 3 | # 4 | # Rules that should be run before the ufw command line added rules. Custom 5 | # rules should be added to one of these chains: 6 | # ufw-before-input 7 | # ufw-before-output 8 | # ufw-before-forward 9 | # 10 | 11 | *nat 12 | :PREROUTING ACCEPT [0:0] 13 | -A PREROUTING -p tcp --dport 8080 -j REDIRECT --to-port 80 14 | COMMIT 15 | 16 | # Don't delete these required lines, otherwise there will be errors 17 | *filter 18 | :ufw-before-input - [0:0] 19 | :ufw-before-output - [0:0] 20 | :ufw-before-forward - [0:0] 21 | :ufw-not-local - [0:0] 22 | # End required lines 23 | 24 | 25 | # allow all on loopback 26 | -A ufw-before-input -i lo -j ACCEPT 27 | -A ufw-before-output -o lo -j ACCEPT 28 | 29 | # quickly process packets for which we already have a connection 30 | -A ufw-before-input -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT 31 | -A ufw-before-output -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT 32 | -A ufw-before-forward -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT 33 | 34 | # drop INVALID packets (logs these in loglevel medium and higher) 35 | -A ufw-before-input -m conntrack --ctstate INVALID -j ufw-logging-deny 36 | -A ufw-before-input -m conntrack --ctstate INVALID -j DROP 37 | 38 | # ok icmp codes for INPUT 39 | -A ufw-before-input -p icmp --icmp-type destination-unreachable -j ACCEPT 40 | -A ufw-before-input -p icmp --icmp-type time-exceeded -j ACCEPT 41 | -A ufw-before-input -p icmp --icmp-type parameter-problem -j ACCEPT 42 | -A ufw-before-input -p icmp --icmp-type echo-request -j ACCEPT 43 | 44 | # ok icmp code for FORWARD 45 | -A ufw-before-forward -p icmp --icmp-type destination-unreachable -j ACCEPT 46 | -A ufw-before-forward -p icmp --icmp-type time-exceeded -j ACCEPT 47 | -A ufw-before-forward -p icmp --icmp-type parameter-problem -j ACCEPT 48 | -A ufw-before-forward -p icmp --icmp-type echo-request -j ACCEPT 49 | 50 | # allow dhcp client to work 51 | -A ufw-before-input -p udp --sport 67 --dport 68 -j ACCEPT 52 | 53 | # 54 | # ufw-not-local 55 | # 56 | -A ufw-before-input -j ufw-not-local 57 | 58 | # if LOCAL, RETURN 59 | -A ufw-not-local -m addrtype --dst-type LOCAL -j RETURN 60 | 61 | # if MULTICAST, RETURN 62 | -A ufw-not-local -m addrtype --dst-type MULTICAST -j RETURN 63 | 64 | # if BROADCAST, RETURN 65 | -A ufw-not-local -m addrtype --dst-type BROADCAST -j RETURN 66 | 67 | # all other non-local packets are dropped 68 | -A ufw-not-local -m limit --limit 3/min --limit-burst 10 -j ufw-logging-deny 69 | -A ufw-not-local -j DROP 70 | 71 | # allow MULTICAST mDNS for service discovery (be sure the MULTICAST line above 72 | # is uncommented) 73 | -A ufw-before-input -p udp -d 224.0.0.251 --dport 5353 -j ACCEPT 74 | 75 | # allow MULTICAST UPnP for service discovery (be sure the MULTICAST line above 76 | # is uncommented) 77 | -A ufw-before-input -p udp -d 239.255.255.250 --dport 1900 -j ACCEPT 78 | 79 | # don't delete the 'COMMIT' line or these rules won't be processed 80 | COMMIT 81 | -------------------------------------------------------------------------------- /0x13-firewall/README.md: -------------------------------------------------------------------------------- 1 | # Firewall 2 | -------------------------------------------------------------------------------- /0x14-mysql/4-mysql_configuration_primary: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2014, 2023, Oracle and/or its affiliates. 2 | # 3 | # This program is free software; you can redistribute it and/or modify 4 | # it under the terms of the GNU General Public License, version 2.0, 5 | # as published by the Free Software Foundation. 6 | # 7 | # This program is also distributed with certain software (including 8 | # but not limited to OpenSSL) that is licensed under separate terms, 9 | # as designated in a particular file or component or in included license 10 | # documentation. The authors of MySQL hereby grant you an additional 11 | # permission to link the program and your derivative works with the 12 | # separately licensed software that they have included with MySQL. 13 | # 14 | # This program is distributed in the hope that it will be useful, 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | # GNU General Public License, version 2.0, for more details. 18 | # 19 | # You should have received a copy of the GNU General Public License 20 | # along with this program; if not, write to the Free Software 21 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 | 23 | # 24 | # The MySQL Server configuration file. 25 | # 26 | # For explanations see 27 | # http://dev.mysql.com/doc/mysql/en/server-system-variables.html 28 | 29 | [mysqld] 30 | binlog_do_db = tyrell_corp 31 | log_bin = /var/log/mysql/mysql-bin.log 32 | server-id = 1 33 | pid-file = /var/run/mysqld/mysqld.pid 34 | socket = /var/run/mysqld/mysqld.sock 35 | datadir = /var/lib/mysql 36 | log-error = /var/log/mysql/error.log 37 | # By default we only accept connections from localhost 38 | bind-address = 127.0.0.1 39 | # Disabling symbolic-links is recommended to prevent assorted security risks 40 | symbolic-links=0 41 | -------------------------------------------------------------------------------- /0x14-mysql/4-mysql_configuration_replica: -------------------------------------------------------------------------------- 1 | # This program is free software; you can redistribute it and/or modify 2 | # it under the terms of the GNU General Public License, version 2.0, 3 | # as published by the Free Software Foundation. 4 | # 5 | # This program is also distributed with certain software (including 6 | # but not limited to OpenSSL) that is licensed under separate terms, 7 | # as designated in a particular file or component or in included license 8 | # documentation. The authors of MySQL hereby grant you an additional 9 | # permission to link the program and your derivative works with the 10 | # separately licensed software that they have included with MySQL. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License, version 2.0, for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program; if not, write to the Free Software 19 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | 21 | # 22 | # The MySQL Server configuration file. 23 | # 24 | # For explanations see 25 | # http://dev.mysql.com/doc/mysql/en/server-system-variables.html 26 | 27 | [mysqld] 28 | binlog_do_db = tyrell_corp 29 | relay-log = /var/log/mysql/mysql-relay-bin.log 30 | log_bin = /var/log/mysql/mysql-bin.log 31 | server-id = 2 32 | pid-file = /var/run/mysqld/mysqld.pid 33 | socket = /var/run/mysqld/mysqld.sock 34 | datadir = /var/lib/mysql 35 | log-error = /var/log/mysql/error.log 36 | # By default we only accept connections from localhost 37 | bind-address = 127.0.0.1 38 | # Disabling symbolic-links is recommended to prevent assorted security risks 39 | symbolic-links=0 40 | -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /0x14-mysql/README.md: -------------------------------------------------------------------------------- 1 | # Install MYSQL 2 | 3 | Install Mysql Server on both servers 4 | -------------------------------------------------------------------------------- /0x14-mysql/install_log: -------------------------------------------------------------------------------- 1 | sudo apt-key add signature.key 2 | sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys B7B3B788A8D3785C 3 | sudo sh -c 'echo "deb http://repo.mysql.com/apt/ubuntu bionic mysql-5.7" >> /etc/apt/sources.list.d/mysql.list' 4 | sudo apt-get update 5 | sudo apt-cache policy mysql-server 6 | sudo apt install -f -y mysql-client=5.7* mysql-community-server=5.7* mysql-server=5.7* 7 | -------------------------------------------------------------------------------- /0x14-mysql/replication: -------------------------------------------------------------------------------- 1 | web01 - CREATE USER slave@'%' IDENTIFIED BY 'password'; 2 | web01 - GRANT REPLICATION SLAVE ON *.* TO slave@'%'; 3 | web01 - FLUSH PRIVILEGES; 4 | web01 - SHOW MASTER STATUS; 5 | 6 | web02 - CHANGE MASTER TO MASTER_HOST='10.0.0.156', MASTER_USER='repl', MASTER_PASSWORD='slavepass', MASTER_LOG_FILE='recorded_log_file_name', MASTER_LOG_POS=log_position; 7 | web02 - START SLAVE; 8 | 9 | sudo service mysql restart 10 | -------------------------------------------------------------------------------- /0x14-mysql/setup.sql: -------------------------------------------------------------------------------- 1 | CREATE USER holberton_user@localhost IDENTIFIED BY "projectcorrection280hbtn"; 2 | GRANT REPLICATION CLIENT ON *.* TO 'holberton_user'@'localhost'; 3 | CREATE DATABASE tyrell_corp; 4 | USE tyrell_corp; 5 | CREATE TABLE nexus6(id INTEGER, name TEXT); 6 | INSERT INTO nexus6 VALUES (0, "Jarvis"); 7 | GRANT SELECT ON tyrell_corp.nexus6 TO holberton_user@localhost; 8 | CREATE USER replica_user@'%' IDENTIFIED BY "replica_user"; 9 | GRANT REPLICATION SLAVE ON *.* TO 'replica_user'@'%'; 10 | GRANT SELECT ON mysql.user TO holberton_user@localhost; 11 | CREATE USER web02@34.227.101.160 IDENTIFIED BY "web02"; 12 | GRANT REPLICATION SLAVE ON *.* TO web02@34.227.101.160; 13 | -------------------------------------------------------------------------------- /0x14-mysql/setup_master: -------------------------------------------------------------------------------- 1 | sudo ufw disable 2 | config_data=\ 3 | " 4 | # The MySQL Server configuration file. 5 | # 6 | # For explanations see 7 | # http://dev.mysql.com/doc/mysql/en/server-system-variables.html 8 | 9 | [mysqld] 10 | binlog_do_db = tyrell_corp 11 | log_bin = /var/log/mysql/mysql-bin.log 12 | server-id = 1 13 | pid-file = /var/run/mysqld/mysqld.pid 14 | socket = /var/run/mysqld/mysqld.sock 15 | datadir = /var/lib/mysql 16 | log-error = /var/log/mysql/error.log 17 | # By default we only accept connections from localhost 18 | bind-address = 0.0.0.0 19 | # Disabling symbolic-links is recommended to prevent assorted security risks 20 | symbolic-links=0 21 | " 22 | 23 | echo "$config_data" | sudo dd status=none of=/etc/mysql/mysql.conf.d/mysqld.cnf 24 | sudo service mysql restart 25 | 26 | echo "Done!!!" 27 | -------------------------------------------------------------------------------- /0x14-mysql/setup_slave: -------------------------------------------------------------------------------- 1 | sudo ufw disable 2 | config_data=\ 3 | " 4 | # The MySQL Server configuration file. 5 | # 6 | # For explanations see 7 | # http://dev.mysql.com/doc/mysql/en/server-system-variables.html 8 | 9 | # The MySQL Server configuration file. 10 | # 11 | # For explanations see 12 | # http://dev.mysql.com/doc/mysql/en/server-system-variables.html 13 | 14 | [mysqld] 15 | binlog_do_db = tyrell_corp 16 | relay-log = /var/log/mysql/mysql-relay-bin.log 17 | log_bin = /var/log/mysql/mysql-bin.log 18 | server-id = 2 19 | pid-file = /var/run/mysqld/mysqld.pid 20 | socket = /var/run/mysqld/mysqld.sock 21 | datadir = /var/lib/mysql 22 | log-error = /var/log/mysql/error.log 23 | # By default we only accept connections from localhost 24 | bind-address = 127.0.0.1 25 | # Disabling symbolic-links is recommended to prevent assorted security risks 26 | symbolic-links=0 27 | " 28 | echo "$config_data" | sudo dd status=none of=/etc/mysql/mysql.conf.d/mysqld.cnf 29 | 30 | sudo service mysql restart 31 | echo "Done!!" 32 | -------------------------------------------------------------------------------- /0x15-api/0-gather_data_from_an_API.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | ''' 3 | gather employee data from 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 | req = requests.get('{}/users/{}'.format(REST_API, id)).json() 17 | task_req = requests.get('{}/todos'.format(REST_API)).json() 18 | emp_name = 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/1-export_to_CSV.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ Export api to csv""" 3 | import csv 4 | import requests 5 | import sys 6 | 7 | if __name__ == '__main__': 8 | user = sys.argv[1] 9 | url_user = 'https://jsonplaceholder.typicode.com/users/' + user 10 | res = requests.get(url_user) 11 | """ANYTHING""" 12 | user_name = res.json().get('username') 13 | task = url_user + '/todos' 14 | res = requests.get(task) 15 | tasks = res.json() 16 | 17 | with open('{}.csv'.format(user), 'w') as csvfile: 18 | for task in tasks: 19 | completed = task.get('completed') 20 | """Complete""" 21 | title_task = task.get('title') 22 | """Done""" 23 | csvfile.write('"{}","{}","{}","{}"\n'.format( 24 | user, user_name, completed, title_task)) 25 | -------------------------------------------------------------------------------- /0x15-api/2-export_to_JSON.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ Python to get data from an API and convert to Json""" 3 | import csv 4 | import json 5 | import requests 6 | import sys 7 | 8 | 9 | if __name__ == '__main__': 10 | USER_ID = sys.argv[1] 11 | url_to_user = 'https://jsonplaceholder.typicode.com/users/' + USER_ID 12 | res = requests.get(url_to_user) 13 | """Documentation""" 14 | USERNAME = res.json().get('username') 15 | """Documentation""" 16 | url_to_task = url_to_user + '/todos' 17 | res = requests.get(url_to_task) 18 | tasks = res.json() 19 | 20 | dict_data = {USER_ID: []} 21 | for task in tasks: 22 | TASK_COMPLETED_STATUS = task.get('completed') 23 | TASK_TITLE = task.get('title') 24 | dict_data[USER_ID].append({ 25 | "task": TASK_TITLE, 26 | "completed": TASK_COMPLETED_STATUS, 27 | "username": USERNAME}) 28 | """print(dict_data)""" 29 | with open('{}.json'.format(USER_ID), 'w') as f: 30 | json.dump(dict_data, f) 31 | -------------------------------------------------------------------------------- /0x15-api/3-dictionary_of_list_of_dictionaries.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """python script to fetch Rest API for todo lists of employees""" 3 | 4 | import json 5 | import requests 6 | import sys 7 | 8 | 9 | if __name__ == '__main__': 10 | url = "https://jsonplaceholder.typicode.com/users" 11 | 12 | resp = requests.get(url) 13 | Users = resp.json() 14 | 15 | users_dict = {} 16 | for user in Users: 17 | USER_ID = user.get('id') 18 | USERNAME = user.get('username') 19 | url = 'https://jsonplaceholder.typicode.com/users/{}'.format(USER_ID) 20 | url = url + '/todos/' 21 | resp = requests.get(url) 22 | 23 | tasks = resp.json() 24 | users_dict[USER_ID] = [] 25 | for task in tasks: 26 | TASK_COMPLETED_STATUS = task.get('completed') 27 | TASK_TITLE = task.get('title') 28 | users_dict[USER_ID].append({ 29 | "task": TASK_TITLE, 30 | "completed": TASK_COMPLETED_STATUS, 31 | "username": USERNAME 32 | }) 33 | """A little Something""" 34 | with open('todo_all_employees.json', 'w') as f: 35 | json.dump(users_dict, f) 36 | -------------------------------------------------------------------------------- /0x15-api/AUTHORS: -------------------------------------------------------------------------------- 1 | Opeoluwa Adeyeri -------------------------------------------------------------------------------- /0x15-api/README.md: -------------------------------------------------------------------------------- 1 | # API -------------------------------------------------------------------------------- /0x16-api_advanced/0-subs.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 3 | Script that queries subscribers on a given Reddit subreddit. 4 | """ 5 | 6 | import requests 7 | 8 | 9 | def number_of_subscribers(subreddit): 10 | """Return the total number of subscribers on a given subreddit.""" 11 | url = "https://www.reddit.com/r/{}/about.json".format(subreddit) 12 | headers = {"User-Agent": "Mozilla/5.0"} 13 | response = requests.get(url, headers=headers, allow_redirects=False) 14 | if response.status_code == 200: 15 | data = response.json() 16 | subscribers = data['data']['subscribers'] 17 | return subscribers 18 | else: 19 | return 0 20 | -------------------------------------------------------------------------------- /0x16-api_advanced/1-top_ten.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | ''' 3 | this module contains the function top_ten 4 | ''' 5 | import requests 6 | from sys import argv 7 | 8 | 9 | def top_ten(subreddit): 10 | ''' 11 | returns the top ten posts for a given subreddit 12 | ''' 13 | user = {'User-Agent': 'Lizzie'} 14 | url = requests.get('https://www.reddit.com/r/{}/hot/.json?limit=10' 15 | .format(subreddit), headers=user).json() 16 | try: 17 | for post in url.get('data').get('children'): 18 | print(post.get('data').get('title')) 19 | except Exception: 20 | print(None) 21 | 22 | 23 | if __name__ == "__main__": 24 | top_ten(argv[1]) 25 | -------------------------------------------------------------------------------- /0x16-api_advanced/100-count.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ Module for a function that queries the Reddit API recursively.""" 3 | 4 | 5 | import requests 6 | 7 | 8 | def count_words(subreddit, word_list, after='', word_dict={}): 9 | """ A function that queries the Reddit API parses the title of 10 | all hot articles, and prints a sorted count of given keywords 11 | (case-insensitive, delimited by spaces. 12 | Javascript should count as javascript, but java should not). 13 | If no posts match or the subreddit is invalid, it prints nothing. 14 | """ 15 | 16 | if not word_dict: 17 | for word in word_list: 18 | if word.lower() not in word_dict: 19 | word_dict[word.lower()] = 0 20 | 21 | if after is None: 22 | wordict = sorted(word_dict.items(), key=lambda x: (-x[1], x[0])) 23 | for word in wordict: 24 | if word[1]: 25 | print('{}: {}'.format(word[0], word[1])) 26 | return None 27 | 28 | url = 'https://www.reddit.com/r/{}/hot/.json'.format(subreddit) 29 | header = {'user-agent': 'redquery'} 30 | parameters = {'limit': 100, 'after': after} 31 | response = requests.get(url, headers=header, params=parameters, 32 | allow_redirects=False) 33 | 34 | if response.status_code != 200: 35 | return None 36 | 37 | try: 38 | hot = response.json()['data']['children'] 39 | aft = response.json()['data']['after'] 40 | for post in hot: 41 | title = post['data']['title'] 42 | lower = [word.lower() for word in title.split(' ')] 43 | 44 | for word in word_dict.keys(): 45 | word_dict[word] += lower.count(word) 46 | 47 | except Exception: 48 | return None 49 | 50 | count_words(subreddit, word_list, aft, word_dict) 51 | -------------------------------------------------------------------------------- /0x16-api_advanced/2-recurse.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Contains recurse function""" 3 | import requests 4 | 5 | 6 | def recurse(subreddit, hot_list=[], after="", count=0): 7 | """Returns a list of titles of all hot posts on a given subreddit.""" 8 | url = "https://www.reddit.com/r/{}/hot/.json".format(subreddit) 9 | headers = { 10 | "User-Agent": "0x16-api_advanced:project:\ 11 | v1.0.0 (by /u/firdaus_cartoon_jr)" 12 | } 13 | params = { 14 | "after": after, 15 | "count": count, 16 | "limit": 100 17 | } 18 | response = requests.get(url, headers=headers, params=params, 19 | allow_redirects=False) 20 | if response.status_code == 404: 21 | return None 22 | 23 | results = response.json().get("data") 24 | after = results.get("after") 25 | count += results.get("dist") 26 | for c in results.get("children"): 27 | hot_list.append(c.get("data").get("title")) 28 | 29 | if after is not None: 30 | return recurse(subreddit, hot_list, after, count) 31 | return hot_list 32 | -------------------------------------------------------------------------------- /0x16-api_advanced/README.md: -------------------------------------------------------------------------------- 1 | # API ADVANCED -------------------------------------------------------------------------------- /0x17-web_stack_debugging_3/0-strace_is_your_friend.pp: -------------------------------------------------------------------------------- 1 | # Fixes bad `phpp` extensions to `php` in the WordPress file `wp-settings.php`. 2 | 3 | exec { 'fix-wordpress': 4 | command => 'sed -i s/phpp/php/g /var/www/html/wp-settings.php', 5 | path => '/usr/local/bin/:/bin/' 6 | } 7 | -------------------------------------------------------------------------------- /0x17-web_stack_debugging_3/README.md: -------------------------------------------------------------------------------- 1 | # README -------------------------------------------------------------------------------- /0x18-webstack_monitoring/README.md: -------------------------------------------------------------------------------- 1 | # Datadog -------------------------------------------------------------------------------- /0x1A-application_server/2-app_server-nginx_config: -------------------------------------------------------------------------------- 1 | server { 2 | listen 80; 3 | listen [::]:80 default_server; 4 | add_header X-Served-By $hostname; 5 | root /etc/nginx/html; 6 | index index.html index.htm; 7 | location /redirect_me { 8 | return 301 https://www.youtube.com/watch?v=QH2-TGUlwu4; 9 | } 10 | root /var/www/html; 11 | 12 | server_name _; 13 | 14 | location /airbnb-onepage { 15 | proxy_pass http://0.0.0.0:5000/airbnb-onepage; 16 | } 17 | 18 | location /hbnb_static { 19 | alias /data/web_static/current/; 20 | } 21 | 22 | location /{ 23 | # First attempt to serve request as file, then 24 | # as directory, then fall back to displaying a 404. 25 | try_files $uri $uri/ =404; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /0x1A-application_server/3-app_server-nginx_config: -------------------------------------------------------------------------------- 1 | server { 2 | listen 80 default_server; 3 | location /hbnb_static { alias /data/web_static/current/;} 4 | listen [::]:80 default_server; 5 | root /var/www/html; 6 | index index.html index.htm index.nginx-debian.html 7 | server_name_; 8 | add_header X-Served-By $hostname; 9 | location / { 10 | try_files $uri $uri/ =404; 11 | } 12 | location /airbnb-onepage { 13 | proxy_pass http://0.0.0.0:5000/airbnb-onepage; 14 | } 15 | location ~ ^/airbnb-dynamic/number_odd_or_even/([0-9]+)$ { 16 | proxy_pass http://0.0.0.0:5001/number_odd_or_even/$1; 17 | } 18 | if ($request_filename ~ redirect_me){ 19 | rewrite ^ https://th3-gr00t.tk/ permanent; 20 | } 21 | error_page 404 /error_404.html; 22 | location = /error_404.html { 23 | internal; 24 | } 25 | } 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /0x1A-application_server/4-app_server-nginx_config: -------------------------------------------------------------------------------- 1 | server { 2 | listen 80 default_server; 3 | location /hbnb_static { alias /data/web_static/current/;} 4 | listen [::]:80 default_server; 5 | root /var/www/html; 6 | index index.html index.htm index.nginx-debian.html 7 | server_name_; 8 | add_header X-Served-By $hostname; 9 | location / { 10 | try_files $uri $uri/ =404; 11 | } 12 | location /airbnb-onepage { 13 | proxy_pass http://0.0.0.0:5000/airbnb-onepage; 14 | } 15 | location ~ ^/airbnb-dynamic/number_odd_or_even/([0-9]+)$ { 16 | proxy_pass http://0.0.0.0:5001/number_odd_or_even/$1; 17 | } 18 | location /api/ { 19 | proxy_pass http://0.0.0.0:5002; 20 | } 21 | if ($request_filename ~ redirect_me){ 22 | rewrite ^ https://th3-gr00t.tk/ permanent; 23 | } 24 | error_page 404 /error_404.html; 25 | location = /error_404.html { 26 | internal; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /0x1A-application_server/4-reload_gunicorn_no_downtime: -------------------------------------------------------------------------------- 1 | Lets see 2 | -------------------------------------------------------------------------------- /0x1A-application_server/5-app_server-nginx_config: -------------------------------------------------------------------------------- 1 | server { 2 | listen 80 default_server; 3 | location /hbnb_static { alias /data/web_static/current/;} 4 | listen [::]:80 default_server; 5 | root /var/www/html; 6 | index index.html index.htm index.nginx-debian.html 7 | server_name_; 8 | add_header X-Served-By $hostname; 9 | location /static/ { 10 | # rewrite ^(/static/[^?]*)\?.*$ $1 last; 11 | alias /home/ubuntu/AirBnB_clone_v4/web_dynamic/static/; 12 | try_files $uri $uri/ =404; 13 | } 14 | location / { 15 | try_files $uri $uri/ =404; 16 | } 17 | location /airbnb-onepage { 18 | proxy_pass http://0.0.0.0:5000/airbnb-onepage; 19 | } 20 | location ~ ^/airbnb-dynamic/number_odd_or_even/([0-9]+)$ { 21 | proxy_pass http://0.0.0.0:5001/number_odd_or_even/$1; 22 | } 23 | location /api/ { 24 | proxy_pass http://0.0.0.0:5002; 25 | } 26 | if ($request_filename ~ redirect_me){ 27 | rewrite ^ https://th3-gr00t.tk/ permanent; 28 | } 29 | error_page 404 /error_404.html; 30 | location = /error_404.html { 31 | internal; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /0x1A-application_server/README.md: -------------------------------------------------------------------------------- 1 | # APPLICATION SERVER 2 | -------------------------------------------------------------------------------- /0x1A-application_server/app-server: -------------------------------------------------------------------------------- 1 | echo "Updating Packages and Installing Requirements" 2 | 3 | # Update Package Manager 4 | sudo apt-get update 5 | sudo apt-get install -y nginx 6 | # Install pip 7 | sudo apt-get install -y python3-pip 8 | # Install Flask, flask_cors, sqlalchemy Using PIP 9 | pip install flask 10 | pip install flask_cors 11 | pip install sqlalchemy 12 | # Install net-tools 13 | sudo apt install -y net-tools 14 | # Install GUNICORN 15 | sudo apt-get install -y gunicorn 16 | # Remove any current AIRBNB Repositoty 17 | rm -rf AirBnB_clone_v* 18 | # Clone My Repository 19 | git clone https://github.com/hardope/AirBnB_clone_v2 20 | git clone https://github.com/hardope/AirBnB_clone_v3 21 | git clone https://github.com/hardope/AirBnB_clone_v4 22 | # Change Directory 23 | cd AirBnB_clone_v2 24 | # Switch Branches 25 | git checkout app-server 26 | 27 | # Define the path to the Nginx configuration file to be overwritten 28 | NGINX_CONFIG="/etc/nginx/sites-enabled/default" 29 | 30 | # Overwrite the Nginx configuration file with the provided configuration 31 | sudo tee "$NGINX_CONFIG" > /dev/null < 'sed -i "s/15/10000/" /etc/default/nginx && sudo service nginx restart', 5 | path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games', 6 | } 7 | -------------------------------------------------------------------------------- /0x1B-web_stack_debugging_4/1-user_limit.pp: -------------------------------------------------------------------------------- 1 | # Change the OS configuration so that it is possible to login with the 2 | # holberton user and open a file without any error message. 3 | 4 | exec {'OS security config': 5 | command => 'sed -i "s/holberton/foo/" /etc/security/limits.conf', 6 | path => '/usr/bin/env/:/bin/:/usr/bin/:/usr/sbin/' 7 | } 8 | -------------------------------------------------------------------------------- /0x1B-web_stack_debugging_4/README.md: -------------------------------------------------------------------------------- 1 | # 0x1B-web_stack_debugging_4 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ALX System Engineering & DevOps 2 | 3 | * Bash 4 | * Shell Scripting 5 | * Linux 6 | * Ubuntu servers 7 | 8 | --- 9 | 10 | - [0x00](./0x00-shell_basics) : Writing basic bash scripts that perform basic stuff. 11 | - [0x01](./0x01-shell_permissions) : Linux permissions. 12 | - [0x02](./0x02-shell_redirections) : Shell, I/O Redirections and filters. 13 | - [0x03](./0x03-shell_variables_expansions) : Shell, init files, variables and expansions. 14 | - [0x04](./0x04-loops_conditions_and_parsing) : Loops, conditions and parsing. 15 | - [0x05](./0x05-processes_and_signals) : Processes and signals. 16 | - [0x06](./0x06-regular_expressions) : Regular expression. 17 | - [0x07](./0x07-networking_basics) : Networking basics #0. 18 | - [0x08](./0x08-networking_basics_2) : Networking basics #1. 19 | - [0x09](./0x09-web_infrastructure_design) : Web infrastructure design. 20 | - [0x0A](./0x0A-configuration_management) : Configuration management. 21 | - [0x0B](./0x0B-ssh) : SSH. 22 | - [0x0C](./0x0C-web_server) : Web server. 23 | - [0x0D](./0x0D-web_stack_debugging_0) : Web stack debugging #0. 24 | - [0x0E](./0x0E-web_stack_debugging_1) : Web stack debugging #1. 25 | - [0x0F](./0x0F-load_balancer) : Load balancer. 26 | - [0x10](./0x10-https_ssl) : HTTPS SSL. 27 | - [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. 28 | - [0x12](./0x12-web_stack_debugging_2) : Web stack debugging #2. 29 | - [0x13](./0x13-firewall) : Firewall. 30 | - [0x14](./0x14-mysql) : MySQL. 31 | - [0x15](./0x15-api) : API. 32 | 33 | -------------------------------------------------------------------------------- /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/hardope/alx-system_engineering-devops/dd88b5396fa91e3e23dd881a45175ae3522506ae/attack_is_the_best_defense/user_authenticating_into_server -------------------------------------------------------------------------------- /command_line_for_the_win/README.md: -------------------------------------------------------------------------------- 1 | # command_line_for_the_win 2 | --------------------------------------------------------------------------------