You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In sleep mode, the content of ram is kept as it is,
and the computer works on a very low power mode,
so as to keep the ram content intact (as ram will
lose the data if power supply is cut to it).
But in hibernation, the ram content is stored in the swap space,
so power can be completely cut off. Hence it is
recommended to have swap size as large as the ram size.
First disable the swap and delete it
$ sudo swapoff /swapfile
$ sudo rm /swapfile
Create new swap space of size 16 GB (16 * 1024 = 16384).
bs is the block size. Basically bs * count = bytes to
be allocated (in this case 16 GB). Here bs = 1M
(M stands for mega, so we are assigning 1MB block size) and
we are allocating 16384 * 1MB (=16GB) to swap.
$ sudo dd if=/dev/zero of=/swapfile bs=1M count=16384
Give it the read/write permission for root
$ sudo chmod 600 /swapfile
Format it to swap
$ sudo mkswap /swapfile
Turn on swap again
$ sudo swapon /swapfile
Now reboot the PC for the above changes to take place.
# clean install
$ sudo apt-get remove nodejs ^node-* nodejs-*
$ sudo apt-get autoremove
$ sudo apt-get clean
# apt
$ sudo apt install nodejs
$ sudo apt install npm
# stable release
$ curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
$ sudo apt-get install -y nodejs
# optional
$ sudo apt install libssl1.0-dev
$ sudo apt install node-gyp
$ sudo apt install npm
# configure npm without sudo
# list currently installed packages
$ npm list -g --depth=0
# npm to install packages to home
$ npm config get prefix
$ npm config set prefix ~/npm
# fix your paths
$ nano ~/.bashrc
# add these lines:
> export PATH="$PATH:$HOME/npm/bin"
> export NODE_PATH="$NODE_PATH:$HOME/npm/lib/node_modules"
$ . ~/.bashrc
# take ownership
$ ls -la ~/.npm
$ sudo chown -R $USER:`id -g -n $USER` ~/.npm
# update your .bash_profile
# add this line:
> source ~/.bashrc
Installing PM2 (Optional)
$ npm install pm2@latest -g
$ pm2 start your_app.js
# run pm2 on startup
$ pm2 startup systemd
# The last line of the resulting output will include a command
# to run with superuser privileges in order to set PM2 to start on boot:
# Output:
[PM2] Init System found: systemd
[PM2] To setup the Startup Script, copy/paste the following command:
sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u username --hp /home/username
# Run the command from the output, with your username in place of username:
$ sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u username --hp /home/username
# As an additional step, we can save the PM2 process list and corresponding environments:
$ pm2 save
# You have now created a systemd unit that runs pm2 for your user on boot.
# This pm2 instance, in turn, runs hello.js.
# Start the service with systemctl:
$ sudo systemctl start pm2-username
# Check the status of the systemd unit:
$ systemctl status pm2-username
# Stop an application with this command (specify the PM2 App name or id):
$ pm2 stop app_name_or_id
# Restart an application:
$ pm2 restart app_name_or_id
# List the applications currently managed by PM2:
$ pm2 list
# Get information about a specific application using its App name:
$ pm2 info app_name
# The PM2 process monitor can be pulled up with the monit subcommand.
# This displays the application status, CPU, and memory usage:
$ pm2 monit
Setting Up Nginx as a Reverse Proxy Server (Optional)
$ sudo apt install -y mongodb
# check status
$ sudo systemctl status mongodb
$ mongo --eval 'db.runCommand({ connectionStatus: 1 })'
# status
$ sudo systemctl status mongodb
# stop
$ sudo systemctl stop mongodb
# start
$ sudo systemctl start mongodb
# restart
$ sudo systemctl restart mongodb
# disable on restart
$ sudo systemctl disable mongodb
# enable on restart
$ sudo systemctl enable mongodb
# Adjusting the Firewall (Optional)
# allow other server to connect
$ sudo ufw allow from {your_other_server_ip}/32 to any port 27017
Secure Mongo
Terminal 1:
$ mongod --auth
Terminal 2:
$ db.createUser({user:"admin_name", pwd:"1234",roles:["readWrite","dbAdmin"]})
if you want to add without roles (optional):
$ db.createUser({user:"admin_name", pwd:"1234", roles:[]})
to check if authenticated or not:
$ db.auth("admin_name", "1234")
it should give you:
1
else :
Error: Authentication failed.
0
Install MySQL
# stop mysql before reinstalling
$ sudo pkill mysql
$ sudo pkill mysqld
# clean install
$ sudo apt-get remove --purge mysql*
$ sudo apt-get purge mysql*
$ sudo apt-get autoremove
$ sudo apt-get autoclean
$ sudo apt-get remove dbconfig-mysql
$ sudo apt install mysql-server
$ sudo mysql_secure_installation
# create new mysql user non-sudo
$ sudo mysql -u root -p
> CREATE USER 'user_name'@'localhost' IDENTIFIED BY 'your_password';> CREATE DATABASE your_database_name;> GRANT ALL PRIVILEGES ON your_database_name.* TO 'user_name'@'localhost';> FLUSH PRIVILEGES;# remove sudo (development)
$ sudo mysql -u root -p
> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '';# create new super user or another root (optional)> GRANT ALL PRIVILEGES ON *.* TO 'your_root_username'@'localhost';# Rename user> RENAME USER 'username'@'host' TO 'new_username'@'localhost';# Allow remote login (WARNING)> CREATE USER 'root'@'%' IDENTIFIED BY 'root';> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;# Remove password (for development ONLY)> SHOW VARIABLES LIKE 'validate_password%';> SET GLOBAL validate_password.number_count = 0;> SET GLOBAL validate_password.length = 0;> SET GLOBAL validate_password.mixed_case_count = 0;> SET GLOBAL validate_password.policy = 0;> SET GLOBAL validate_password.special_char_count = 0;> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_new_password';# Legacy password (Warning)> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';# Delete or remove user> DROP USER 'username'@'localhost';# Start and Stop
$ sudo service mysql start
$ sudo service mysql stop
# Make sure date and time is correct> SELECT CURDATE();
1. Allow Apache access to the folders and the files.
$ sudo chgrp -R www-data /var/www/html
$ sudo find /var/www/html -type d -exec chmod g+rx {} +
$ sudo find /var/www/html -type f -exec chmod g+r {} +
2. Give your owner read/write privileges to the folders and the files,
and permit folder access to traverse the directory structure.
$ sudo chown -R {username} /var/www/html/
$ sudo find /var/www/html -type d -exec chmod u+rwx {} +
$ sudo find /var/www/html -type f -exec chmod u+rw {} +
3. (Optional) Make sure every new file after this is created with www-data as the 'access' user.
$ sudo find /var/www/html -type d -exec chmod g+s {} +
4. (Optional) Final security cleanup, if you don't want other users to be able to see the data
$ sudo chmod -R o-rwx /var/www/html/
$ sudo apt-get install vsftpd
1. Update the file
$ sudo nano /etc/vsftpd.conf
> anonymous_enable=Yes
# To allow local users to login, edit the /etc/vsftpd.conf file by changing.
> local_enable=YES
> local_umask=022
# To grant local users to write to a directory change the write_enable setting to YES.
> write_enable=YES
# Local users can be limited to their home directories by uncommenting.
> chroot_local_user=YES
> allow_writeable_chroot=YES
# Restart ftp
$ service vsftpd restart
# Allo to firewall (ufw)
$ sudo ufw allow 20/tcp
$ sudo ufw allow 21/tcp
$ sudo ufw allow 990/tcp
$ sudo ufw allow 40000:50000/tcp
$ sudo ufw status
$ sudo nano /etc/crontab
# add to your cron job (run every minute)
> * * * * * {username} php /{your-app-folder}/artisan schedule:run >> /dev/null 2>&1
# to run every hour
> 0 * * * *
# restart cron
$ sudo service cron restart
# syntax
1 2 3 4 5 USERNAME /path/to/command arg1 arg2
1: Minute (0-59)
2: Hours (0-23)
3: Day (0-31)
4: Month (0-12 [12 == December])
5: Day of the week(0-7 [7 or 0 == sunday])
USERNAME - Name of the user
/path/to/command – Script or command name to schedule
Examples:
The correct syntax is as follows for root user to run a cron job at 00:50 every day.
> 50 0 * * * root /etc/cron.d/backups
Add to path variables
# open and add to .bashrc
$ nano .bashrc
> export PATH="/your-path-to-software/bin:/your-path-to-software/bin:${PATH}"
$ source ~/.bashrc
Configure Network
# list network cards
$ ip link show
# network info
$ netstat -i
# details
$ ifconfig {interface-name}
# update network
$ sudo nano /etc/network/interfaces
# Use NetPlan
# check available config files
$ ls /etc/netplan/
$ sudo nano /etc/netplan/01-netcfg.yaml
> dhcp4: no
> addresses: [192.168.1.8/24]
> gateway4: 192.168.1.1
> nameservers:
> addresses: [8.8.8.8,8.8.4.4]
$ sudo netplan apply
# for debugging
$ sudo netplan --debug apply
# DHCP
> source /etc/network/interfaces.d/*
> # The loopback network interface
> auto lo
> iface lo inet loopback
> # The primary network interface
> auto {interface-name}
> iface {interface-name} inet dhcp
# Static
> source /etc/network/interfaces.d/*
> # The loopback network interface
> auto lo
> iface lo inet loopback
> # The primary network interface
> auto {interface-name}
> iface {interface-name} inet static
> address 192.168.1.1
> netmask 255.255.255.0
> network 192.168.1.0
> broadcst 192.168.0.255
> gateway 192.168.1.1
> dns-nameservers 8.8.8.8
👍