- how to add a port number
- how to show the list of rules
- how to deny a rule/port
- how to delete a rule/port
- how to switch to a different user
- how to add a new user
- how to list local users
- how to delete a user
- how to change a username
- how to change a password
- how to install node.js on ubuntu
- how to install nvm/ or update node
- how to set up wordpress
- how to setup laravel
- how to install phpmyadmin
- how to setup a local host file
- how to enable certain ports
- how to set up a server with ubuntu
- how to change the timezone
- cat
- head
- tail
- less
- tar
- sed
- awk
- sort
View Content
reference
- [nodemon] app crashed - waiting for file changes before starting
- Nodemon: Error: listen EADDRINUSE: address already in use :::5000
lsof -i :3000 -t | xargs kill
View Content
reference
- create an .htaccess file and add this
sudo vim /usr/share/phpmyadmin/.htaccess
...
AuthType Basic
AuthName "Restricted Files"
AuthUserFile /etc/phpmyadmin/.htpasswd
Require valid-user
- now create the .htpasswd for the .htaccess
sudo htpasswd -c /etc/phpmyadmin/.htpasswd insertUsername
// after that it will ask you for a password
- now restart it
sudo service apache2 restart
View Content
reference
- vim inside apache.conf
sudo vim /etc/phpmyadmin/apache.conf
- in the file change the alias which originally has
/phpmyadmin
# Alias /phpmyadmin /usr/share/phpmyadmin
Alias /mynewadmin /usr/share/phpmyadmin
- now reload apache2
sudo service apache2 reload
View Content
reference
- first list the available timezones
timedatectl list-timezones
- find the one you want to use and set it
timedatectl set-timezone "America/New_York"
- if you want to change it back to UTC do this
timedatectl set-timezone UTC
View content
reference
sudo su
// This command give you root privilege so now you don't have to worry about
// any permissions blocking you
View Content
reference
sudo apt-get update
sudo apt-get install software-properties-common
sudo add-apt-repository universe
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
sudo apt-get install certbot python-certbot-apache
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
sudo apt-get install certbot
View Content
sudo certbot --apache -d <insert domain>
View content
reference
here is what worked for me so far
- create a bin file and it into the bashrc if you haven't done it already
mkdir ~/bin
// open up bash
sudo nano ~/.bashrc
// now insert the code
export PATH=$PATH:~/bin
- now create an sh file creating a function
nano ~/bin/hello.sh
//inside hello.sh
print_hello(){
echo "hello world";
}
- make all the files executable
chmod -R +x ~/bin;
- now you can run the file
hello.sh
View content
reference
- An Introduction to Useful Bash Aliases and Functions
- How can I create a custom terminal command (to run a script)?
- open up the
bashrc
file and put your alias command inside of it
sudo nano ~/.bashrc
//inside the bashrc file add your command anywhere
alias .2="cd ../../"
- create a file with some command you want
// create the file
nano sites
// inside sites add your specific command like this
// Note: its important to add a semi-colon at the end
cd /etc/apache2/sites-available;
- now create a bin folder and move the file into the bin
// make the bin
mkdir ~/bin
// move the file in the bin
mv sites ~/bin/sites
- make the files executable
sudo chmod -R +x ~/bin
- now open up the bashrc file and add this code
// open up bash
sudo nano ~/.bashrc
// now insert the code
export PATH=$PATH:~/bin
- so this should make the
sites
command work
View content
reference
Declaring aliases in bash is very straight forward. It's so easy that you should try it now.
The alias keyword will make it alot easier to create custom commands
alias alias_name="command_to_run"
// this should go back 2 folders when you type in ..2
alias ..2="cd ../../"
unalias ..2;
View content
reference
- Install phpMyAdmin on Ubuntu 16.04
- How to solve the phpmyadmin not found issue after upgrading php and apache?
- update linux
sudo apt-get update && apt-get upgrade
- install phpmyadmin
sudo apt-get install phpmyadmin
-
When prompted for a web server choose Apache2
-
In the next prompt click yes to configure a database for phpmyadmin
-
Next, set the password and confirm the password you created to get into phpmyadmin
-
Now add this in the terminal, I'm assuming that you are creating a link connection and then turning on phpmyadmin
sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf-available/phpmyadmin.conf;
sudo a2enconf phpmyadmin.conf;
sudo service apache2 reload
- Now you should be able to go to your site at
http://yourIPaddress/phpmyadmin
- Open up the conf file
sudo nano /etc/apache2/conf-available/phpmyadmin.conf
- On line 3, change the path name
Alias /newPathName /usr/share/phpmyadmin
View content
reference -vim keyboard shortcuts
Command | Explanation |
---|---|
esc | Gets out of the current mode into the โcommand modeโ. All keys are bound of commands. |
: | โLast-line modeโ where Vim expects you to enter a command such as to save the document. |
$ | jumps to the end of line |
0 | jumps to the beginning of line |
dd | deletes a line. |
G | jumps to the end of the file |
gg | jumps to the beginning of the file |
i | โInsert modeโ for inserting text. Keys behave as expected. |
o | Begin a new line below the cursor |
p | paste content |
u | undo the last operation. |
v | Allows you to select multiple text |
d | deletes a character OR cuts selected text |
y | copies selected content |
? | finds a word in the file, and pressing n goes to the next word |
Command | Explanation |
---|---|
v or V | Selects multiple text |
y | copies selected content |
yy | copies current line |
p | paste content after cursor line |
P | paste content before cursor line |
V then d then p | To select text, the cut text, then paste text |
Command | Explanation |
---|---|
G | jumps to the end of the file |
gg | jumps to the beginning of the file |
View content
reference
Command | Explanation |
---|---|
alt + \ | jumps to beginning of file |
alt + / | jumps to end of file |
ctr + 6 | allows you to select multiple lines if you move up or down |
alt + 6 | copies higlighted text |
ctr + a | jumps to end of line |
ctr + e | jumps to beginning of line |
ctr + d | delete content |
alt + r | search and replace |
ctr + k | cut content |
ctr + u | paste content |
reference
- lets encrypt
- Solution: Client with the currently selected authenticator does not support any combination of challenges that will satisfy the CA
- How to stop using TLS-SNI-01 with Certbot
If youโre serving files for that domain out of a directory on that server
sudo certbot --authenticator webroot --webroot-path <path to served directory> --installer apache -d <domain>
If youโre not serving files out of a directory on the server
sudo certbot --authenticator standalone --installer apache -d <domain> --pre-hook "service apache stop" --post-hook "service apache start"
sudo passwd username
usermod -l new_username old_username
- in the terminal
sudo userdel username
- delete home directory of the user
sudo rm -r /home/username
reference
chgrp <new group> <insert path to file>
// changes the group name of a file or folder
chgrp -R <new group> <insert path to file>
// changes the group name of a file or folder recursively
chgrp -f <new group> <insert path to file>
// changes the group name of a file or folder forcefully
reference
grep -i --color 'insert group name' /etc/group
OR
sudo apt install members
members webmaster
useradd -g insertGroup insertUser
usermod -aG insertGroup insertUser
reference
this command sort of works. But, it lists a lot of other commands and the local users at the bottom
cut -d: -f1 /etc/passwd
reference
chown jermaine <insert folder name>
chown :developer <insert folder name>
chown jermaine:developer <insert folder name>
// how to do this recursively
chown -R jermaine:developer <insert folder name>
chown --from=chris jermaine <insert folder name>
chown --from=:production :development <insert folder name>
// this copies the owner and group settings from the file "file"
// and apply it to the file "tmpfile"
chown --reference=file tmpfile
su - <insert name>
sudo adduser <insert name>
reference
- download Let's Encrypt
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
sudo apt-get install python-certbot-apache
- set up the SSL certificate
sudo certbot --apache -d example.com
// if you want to certify multiple domains
sudo certbot --apache -d example.com -d www.example.com
- setup auto renewal
sudo crontab -e
// in the text editor add this
15 3 * * * /usr/bin/certbot renew --quiet
// At 3:15am the certbot will check if the certificates need to be renewed
reference
# | Permission | rwx |
---|---|---|
7 | read,write, and execute | rwx |
6 | read and write | rw- |
5 | read and execute | r-x |
4 | read only | r-- |
3 | write and execute | -wx |
2 | write only | -w- |
1 | execute only | --x |
0 | none | --- |
Reference | Class | Description |
---|---|---|
u | owner | file's owner |
g | group | users who are members of the file's group |
o | others | users who are neither the file's owner nor members of the file's group |
a | all | all three of the above, same as ugo |
Operator | Description |
---|---|
+ | adds the specified modes to the specified classes |
- | removes the specified modes from the specified classes |
= | the modes specified are to be made the exact modes for the specified classes |
Mode | Name | Description |
---|---|---|
r | read | read a file or list a directory's contents |
w | write | write to a file or directory |
x | execute | execute a file or recurse a directory tree |
X | special execute | which is not a permission in itself but rather can be used instead of x. It applies execute permissions to directories regardless of their current permissions and applies execute permissions to a file which already has at least one execute permission bit already set (either owner, group or other). It is only really useful when used with '+' and usually in combination with the -R option for giving group or other access to a big directory tree without setting execute permission on normal files (such as text files), which would normally happen if you just used "chmod -R a+rx .", whereas with 'X' you can do "chmod -R a+rX ." instead |
s | setuid/gid | allows a person to execute a program with the user and groups permmision according to this source |
t | sticky | prevents a file or directory to be renamed or removed examples |
So there are certain words that if you type in the terminal will
execute a function. Essentially they are commands, so if you remove the permission
of execute it will not a script that can run a command. Here is a little trick
I learned, if you create a file like touch run
. This will will create a
file called run, next you should open the file and insert ls -la
. Save the
file and insert the file the terminal to execute the command ./run
this should run the ls -la command. If you remove the execute permission it
will not work... at least I think
reference
the setuid and setgid gives permission for the user and the group to execute
a file so when you do a command chmod o+s ./script
you are giving the permission
for anyone/others to execute the file called script. Not only that, it will execute
the program as if you are the user or group
-rwxr-xr-x 14 jermaine jermaine 4.0K Sep 4 18:00 filename.txt
// gives permission to read and write to the owner and group
chmod 660 filename.txt
-rw-rw---- filename.txt
// owner: read,write, and execute
// group: read,write, and execute
// others: read and write
chmod 776 filename.txt
-rwxrwxrw- filename.txt
// owner: write
// group: write
// others: write
chmod a+w filename.txt
--w--w--w- filename.txt
//-rw--w--w- filename.txt
chmod u=o filename.txt
//-rw--w-rw- filename.txt
the find command tries to find a specific file that is in a specific location
reference
finds name of file in specific path
find ./images -name "dog.jpg"
// prints out the path to dog.jpg, for example
./images/animals/dog.jpg
// AND, you can find files by their extension name
find ./images -name "*.jpg"
.images/animals/dog.jpg
.images/furniture/chair.jpg
.images/entertainment/nudes.jpg
finds name of files and ignores the casing
find ./music -iname 'BLUe*'
./music/I am having a blue day.mp3
./music/Blueberry dreams.mp3
./music/sad and blue.mp3
limits the depth of directory traversal
find ./img -maxdepth 2 -iname "*.png"
./img/eat.png
./img/alphabet/a.png
./img/anatomy/dick.png
find ./img -maxdepth 3 -iname "*.png"
./img/eat.png
./img/alphabet/a.png
./img/anatomy/dick.png
./img/anatomy/bones/femur.png
./img/alphabet/chinese/chingchong.png
excludes the name or file extension
find ./public
style.css
image.jpg
base.js
find ./public ! -name "*.js"
style.css
image.jpg
combine multiple queries
find ./images -name "*.gif"
./images/find.gif
./images/the.gif
find ./images -name "*.gif" ! -name "*e"
./images/find.gif
// Note: the query results will only print out the files that match all the queries
OR
find -name '*.php' -o -name '*.txt'
./abc.txt
./subdir/how.php
./abc.php
./cool.php
// Note: the query results will print out anything that matches the multiple queries
Search only files or only directories
find ./test -name abc*
./test/abc.txt
./test/abc
Only files
find ./test -type f -name "abc*"
./test/abc.txt
Only directories
find ./test -type d -name "abc*"
./test/abc
Find files belonging to particular user
find . -user bob
.
./abc.txt
./abc
./subdir
./subdir/how.php
./abc.php
Search files belonging to group
find /var/www -group developer
Find files accessed in last N days
find / -atime 50
// shows the days which is 50
Find files belonging to particular user
find . -user root
.
./abc.txt
./abc
./subdir
./subdir/how.php
./abc.php
Find files in a size range
find / -size +50M -size -100M
// Different file sizes
G - gigabytes
M - megabytes
k - kilobytes
b - bytes
Find files with certain permissions
find . -type f -perm 0664
./abc.txt
./subdir/how.php
./abc.php
./cool.php
sudo apt-get update upgrade
sudo apt-get install git zip
sudo apt-get install curl php-curl php-mcrypt php-mbstring php-gettext
sudo phpenmod mcrypt; sudo phpenmod mbstring; sudo a2enmod rewrite
sudo service apache2 restart
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
composer create-project laravel/laravel your-project --prefer-dist
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/laravel.conf
sudo nano laravel.conf
// inside laravel.conf
<VirtualHost *:80>
ServerName work.com
DocumentRoot /var/www/html/your-project/public
<Directory /var/www/html/your-project/public>
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
sudo a2ensite laravel.conf; sudo service apache2 reload
cd your-project
sudo chmod -R 755 ./; sudo chmod -R o+w ./storage
reference
this is great for setting creating a websites or at least developing it without having to buy a domain ... for now . This is essentially working apache for the most part and then using your personal computer
- create a conf file for apache
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/test.conf
sudo nano /etc/apache2/sites-available/test.conf
// in the test.conf file, add the ServerName test.com and close the file
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /home/jermaine/test
ServerName test.com
<Directory /home/jermaine/test/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<IfModule mod_dir.c>
DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
</IfModule>
</VirtualHost>
- next enable the site
sudo a2ensite test.conf
sudo service apache2 reload
-
now, go to your personal and run notepad as an administrator
-
once in notepad, open a file to the path
C:\Windows\System32\drivers\etc\hosts
-
now in the hosts file insert your vps ip address and the ServerName
111.111.111.111 test.com
- and that is about it.
This is pretty easy you just type in one command
sudo ufw allow enterPortNumber
reference firewall
- log into mysql and type this into the terminal
CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
- create a user specifically for wordpress and type
GRANT ALL ON wordpress.* TO 'wordpressuser'@'localhost' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
EXIT;
- install the additional php extensions
sudo apt-get update
sudo apt-get install php-curl php-gd php-mbstring php-mcrypt php-xml php-xmlrpc
sudo systemctl restart apache2
- go into apache2.conf file to allow htaccess overrides
sudo nano /etc/apache2/apache2.conf
// add this into the file
<Directory /var/www/html/>
AllowOverride All
</Directory>
- enable the changes and restart apache2
sudo a2enmod rewrite
sudo apache2ctl configtest
sudo systemctl restart apache2
- download wordpress and unzip it
cd /tmp
curl -O https://wordpress.org/latest.tar.gz
tar xzvf latest.tar.gz
- do some shit with wordpress
touch /tmp/wordpress/.htaccess
chmod 660 /tmp/wordpress/.htaccess
cp /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php
mkdir /tmp/wordpress/wp-content/upgrade
sudo cp -a /tmp/wordpress/. /var/www/html
- configure wordpress
sudo chown -R yourName:www-data /var/www/html
sudo find /var/www/html -type d -exec chmod g+s {} \;
sudo chmod g+w /var/www/html/wp-content
sudo chmod -R g+w /var/www/html/wp-content/themes
sudo chmod -R g+w /var/www/html/wp-content/plugins
- creating keys and passwords
// copy the printed keys
curl -s https://api.wordpress.org/secret-key/1.1/salt/
sudo nano /var/www/html/wp-config.php
// place the printed keys in the file
// and add in the database information like this
define('DB_NAME', 'wordpress');
/** MySQL database username */
define('DB_USER', 'wordpressuser');
/** MySQL database password */
define('DB_PASSWORD', 'password');
. . .
define('FS_METHOD', 'direct');
- Setup the apache server to host the wordpress, and then you are done
- Alright so the grep keyword searches through any file that contains the string or words that you are looking for.
- grep does not : search a folder it only searches what a specific file, or the files that are in the current directory/folder
grep "some word" /path/to/file
grep -r "some word" /path/to/file
//Note: it will search every file and every file in each folder
grep -l "some word" /path/to/file
grep -i "some word" /path/to/file
// Note: so it will search for the word whether it be uppercase, lowercase, ect..
grep -w "some word" /path/to/file
egrep "word1|word2" /path/to/file
// Note: you can only search two different phrases or words, not three of more
grep -c "some word" /path/to/file
grep -n "some word" /path/to/file
grep -v "some word" /path/to/file
- Either do one or the other
- here is the repository
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash
- then close the terminal and go back into it again. And check to see if it is working
exit
// once you go back into the terminal
nvm -v
the nvm should change node and npm to the most recent version.
- install node and npm with apt-get
sudo apt-get update
sudo apt-get install nodejs
sudo apt install nodejs-legacy
sudo apt-get install npm
- install node with PPA(personal package archive)
cd ~
curl -sL https://deb.nodesource.com/setup_<insert node.js version> -o nodesource_setup.sh
// you can check the contents of the setup like this
nano nodesource_setup.sh
- then run the setup
sudo bash nodesource_setup.sh
- next add this shit
sudo apt-get install nodejs
sudo apt-get install build-essential
- install node version manager
sudo apt-get update
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash
exit
- log back in and install node
nvm -v
nvm install node
- ssh into your server
ssh root@your_server_ip
- add a new user
adduser jermaine
- give root privileges to your new user
usermod -aG sudo jermaine
- switch to the user account
su - jermaine
- Create an ssh directory and authorized_keys file in the user account
mkdir ~/.ssh
sudo chmod 700 ~/.ssh
sudo nano ~/.ssh/authorized_keys
- add the public key by using cat command to display it
//Personal Computer
cat ~/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAA...
// Inside authorized_keys file
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAA...
- restrict the permissions of the authorized_keys, and exit out of user account
sudo chmod 600 ~/.ssh/authorized_keys
// might have to possibly enter this as well
sudo chown jermaine -R ~/.ssh
exit
- open up ssh configuration
sudo nano /etc/ssh/sshd_config
- make sure all these options have these values, then reload
PasswordAuthentication no
PubkeyAuthentication yes
ChallengeResponseAuthentication no
sudo systemctl reload sshd
// might have to possibly enter this as well
sudo service sshd restart
- set up basic firewall
sudo ufw allow OpenSSH
sudo ufw enable
sudo ufw status
- and I think that is it