Skip to content

Instantly share code, notes, and snippets.

@jaime-ez
Last active March 1, 2017 13:47
Show Gist options
  • Save jaime-ez/e30d2394ff7882468c9609d631f4803a to your computer and use it in GitHub Desktop.
Save jaime-ez/e30d2394ff7882468c9609d631f4803a to your computer and use it in GitHub Desktop.
Some linux tips

Linux tips

Setting permanent user environment variables

source: http://unix.stackexchange.com/questions/21598/how-do-i-set-a-user-environment-variable-permanently-not-session

local

If you are using bash, ash, ksh or some other Bourne-style shell, you can add ABC="123"; export ABC in your .profile file (${HOME}/.profile). This is the default situation on most unix installations, and in particular on Debian.
If your login shell is bash, you can use .bash_profile (${HOME}/.bash_profile) or .bash_login instead.

global

Use /etc/environment file for setting the environment variables. Then add the following line inside the /etc/environment file: ABC="123". Now the ABC variable will be accessible from all the user sessions. To test the variable output first refresh the environment variable using the command source /etc/environment and run echo $ABC.

Setting up a clean UTF-8 environment

source: https://perlgeek.de/en/article/set-up-a-clean-utf8-environment

We choose to use en_US locale as the standard. Therefore we run:

  • sudo export LC_ALL=en_US.UTF-8
  • sudo locale-gen

This will set a clean UTF-8 environment. Alternatively we can write the export command into /etc/environment or .bashrc.

Default user password

source: http://unix.stackexchange.com/questions/108562/is-there-some-default-password-for-a-new-user-in-linux

To answer the literal question: no, there is no default password. Usually by default an account will have an "invalid" password, that is, a password hash that will not be matched by any password at all. In order to be able to log in, a password must be explicitly specified, e.g. by running passwd for the account in question.

Run commands as another user

source: https://www.cyberciti.biz/open-source/command-line-hacks/linux-run-command-as-different-user/

  • option 1: runuser -l userNameHere -c 'command'
  • option 2: su - userNameHere -c 'command'

Option 2 has less overhead. Beware than executing commmands that start a process in the foreground will make the bash sesion hang on that process and therefore you will not return to the original user untill the process goes to background or stops.

Run script as user that has no login shell

source: http://serverfault.com/questions/351046/run-script-as-user-who-has-nologin-shell

run su -s /bin/bash -c '/path/to/your/script' testuser

Keep process running after you logout from shell session

source: https://www.cyberciti.biz/tips/nohup-execute-commands-after-you-exit-from-a-shell-prompt.html

run nohup <command> &

This will allow the command-script to continue running in the background.

Debian permissions

reference: https://wiki.debian.org/Permissions

Change user group

source: https://www.howtogeek.com/50787/add-a-user-to-a-group-or-second-group-on-linux/

usermod -a -G <groupname> username

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment