1. Add new user part of sudoers:
sudo su
useradd dtech
2. Create password:
passwd dtech
3. Make sure it has sudo rights:
cd /etc/sudoers.d/
touch dtech_other_sudoers
chmod 440 dtech_other_sudoers
vi dtech_other_sudoers
dtech ALL=(ALL) NOPASSWD: ALL
# This comment is here to have new line at end of file
4. Enable password authentification:
vi /etc/ssh/sshd_config
5. Add following lines to the very end of the file:
Match User dtech
PasswordAuthentication yes
6. Restart sshd service
service sshd restart
7. Test and you shall now get password prompt only for your user:
ssh dtech@35.171.158.153
dtech@35.171.158.153's password:
Last login: Wed Dec 25 22:17:05 2019
Wednesday, December 25, 2019
Thursday, December 19, 2019
Delete a file that begins with "-"/ hyphen, dash or minus on Linux
Use the following command:
rm -- -filename
rm -- -filename
Saturday, November 30, 2019
Remove CSS round border from iOS devices
Following CSS options must be enabled for your element:
element{
border-radius:0;
-webkit-appearance: none;
}
element{
border-radius:0;
-webkit-appearance: none;
}
Saturday, November 23, 2019
Linux: Find and replace text from file
sed -i 's/text-to-replace/text-new/g' destination-file-path
Linux: Find and remove file in one command
Navigate to folder, find the file and remove using the following command. It also asks for confirmation before removing:
cd /destination-folder-path && find -type f -name filename -exec rm -i {} \;
cd /destination-folder-path && find -type f -name filename -exec rm -i {} \;
Thursday, November 7, 2019
PHP - Get last element from array
//array is called here $arrayVariable
$lastElement=end($arrayVariable);
Example:
If $arrayVariable=["apple","pear","peach","cherry"], the function above is to return cherry.
$lastElement=end($arrayVariable);
Example:
If $arrayVariable=["apple","pear","peach","cherry"], the function above is to return cherry.
Thursday, October 31, 2019
PHP Get current date and insert to MySql Database
0. Make sure field to be inserted is of date type:
1. Get current date in php:
date_default_timezone_set("UTC");
$now=new DateTime();
echo $now->getTimestamp();
2. Connect to database and insert using the following statement:
$sql = "INSERT INTO bins (Number, Text, Created, TTL, Property)
VALUES (".$number.", '".$text."','".date("Y-m-d",$now->getTimestamp())."', '1','Active')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
Subscribe to:
Posts (Atom)
