Showing posts with label Ubuntu. Show all posts
Showing posts with label Ubuntu. Show all posts

Friday, 31 July 2026

set -a to load .env

 ## 1. Why you need `set -a` to load `.env`


There's an important distinction in shells between **shell variables** and **environment variables**:


- **Shell variables** exist only in the current shell session. Child processes do **not** inherit them.

- **Environment variables** (exported variables) are inherited by every child process you spawn from that shell.


When you run `source .env`, the shell reads the file and executes lines like:


```sh

FOO=bar

API_KEY=secret

```


By default, these become **shell variables only** — they're set in your current shell, but if you then launch `uvicorn`, that child process will **not** see `FOO` or `API_KEY`, because they were never exported.


`set -a` (short for `set -o allexport`) changes that behavior: from that point on, **every** variable that gets created or modified is automatically marked for export. So the typical pattern is:


```sh

set -a

source .env

set +a

```


- `set -a` → turn on auto-export

- `source .env` → load the file; all vars are now exported to the environment

- `set +a` → turn it off again (so you don't accidentally export unrelated vars later)

Monday, 18 August 2025

Open port and firewall

// open port and list of process

 sudo ss -tlnp



// firewal status

sudo ufw status

Wednesday, 30 July 2025

Ubuntu when will temp directory be cleared

 In Ubuntu, files within the /tmp directory are generally handled in two primary ways regarding their removal:

  • On System Reboot:
    The most common method of clearing /tmp is during a system reboot. By default, Ubuntu and other Debian-based distributions are configured to remove files from /tmp when the system starts up, particularly if their modification time exceeds a certain threshold defined by the TMPTIME variable in /etc/default/rcSA value of TMPTIME=0 will cause files to be removed regardless of age on boot, while other values specify a grace period (e.g., TMPTIME=7 for 7 days).
  • By systemd-tmpfiles-clean.timer:
    Modern Ubuntu systems often utilize systemd for managing temporary files. The systemd-tmpfiles-clean.timer service is typically configured to run daily and clean up temporary files based on rules defined in /usr/lib/tmpfiles.d/tmp.conf and potentially other configuration files in /etc/tmpfiles.d/These rules specify the age after which files in various temporary directories, including /tmp and /var/tmp, should be removed. For instance, files in /tmp might be cleaned after 10 days of inactivity, and those in /var/tmp after 30 days. 
Therefore, tmp directory files are removed either upon system reboot or periodically by the systemd-tmpfiles-clean.timer service, depending on their age and the system's configuration.

Wednesday, 9 July 2025

Ubuntu set folder permission for inheritance (setfacl) && getfacl

 https://serverfault.com/questions/444867/linux-setfacl-set-all-current-future-files-directories-in-parent-directory-to


sudo setfacl -Rdm g:groupnamehere:rwx /base/path/members/
sudo setfacl -Rm g:groupnamehere:rwx /base/path/members/

R is recursive, which means everything under that directory will have the rule applied to it.
d is default, which means for all future items created under that directory, have these rules apply by default. m is needed to add/modify rules.

The first command, is for new items (hence the d), the second command, is for old/existing items under the folder. Hope this helps someone out as this stuff is a bit complicated and not very intuitive.


U can add others:


sudo setfacl -d -m g:your_group:rwx,o:rx /path/to/parentsudo setfacl -d -m g:your_group:rw,o:r /path/to/parent


for user just do:

setfacl -Rdm user:username:rwx /path/to/file



when u set permission ls -l you will see


drwxr-x---+ 4 root root 4096 Jul 14 11:29 test/


this user and group might be current user copied forlder to here or created here, but the permssion

for setfacl is already applied with + sign


see facl use

getfacl mydir/


cmd:

getfacl myfile.txt
This will output something like:
C++
# file: myfile.txt# owner: user1# group: group1user::rw-user:user2:rwxgroup::r--mask::rwxother::r--
Explanation:
  • # file: myfile.txt: Indicates the file being examined.
  • # owner: user1: Specifies the owner of the file.
  • # group: group1: Specifies the group associated with the file.
  • user::rw-: Defines the permissions for the file owner (read and write).
  • user:user2:rwx: Grants read, write, and execute permissions to user2.
  • group::r--: Specifies the permissions for the primary group (read only).
  • mask::rwx: Indicates the effective permissions for the group and named users.
  • other::r--: Defines the permissions for users who are not the owner or part of the primary group (read only).