Questions tagged [bashrc]
The Bashrc file is used by the Bourne Again Shell in Unix/Linux to set environment variables and run commands.
116 questions
0 votes
0 answers
174 views
Common alias for all users
I migrated all my users from Ubuntu 16.04 to Ubuntu 24.04 by adding them to /etc/passwd, /etc/group and /etc/shadow and then executing mkhomedir_helper for each user, see my blog for details. Today I ...
0 votes
2 answers
176 views
su command not set BASH_VERSION value and not load profile
I have a Ubuntu 20.04 LTS server version and have a strange problem creating a new user and use it in the shell from a ssh connection. The steps to reproduce it: Use he root account to create new ...
2 votes
1 answer
241 views
Why is my bash script not being sourced when opening new tmux pane?
The following logic in .bash_aliases to remove duplicate paths works fine when opening a new terminal: # prune duplicate paths PATHS=("PATH" "LD_LIBRARY_PATH" "C_INCLUDE_PATH&...
0 votes
1 answer
3k views
Refresh kerberos ticket instead of prompting for pam password
Using centralised auth against FreeIPA is working great. In order to use Kerberos SSO when using ssh, scp etc from jumphosts users must initiate their Kerberos tickets first with kinit. I've added ...
0 votes
2 answers
1k views
Use original linux user bashrc also as root user
I extended the bashrc file of my linux user. This file contains extra aliases, functions, whatever is useful. It's synchronized with a playbook across our 100+ servers. When i'm working on linux I ...
3 votes
1 answer
3k views
sourcing environment variable in bashrc: directly vs export from file yields different result - why
I am running systemd via user (i.e. enable-linger $USER) and I interact with services via systemctl --user I noticed a strange issue. Sourcing Type 1 In order for the above systemd to work for a user, ...
0 votes
1 answer
1k views
How to Make the IP Address Appear as Part of Bash Prompt?
Running an Amazon EC2 instance with Ubuntu 22.04. The elastic ip address is 52.120.94.72. I want the bash prompt to read like this (no space) [email protected]:~/working_directory$ Based on some ...
2 votes
1 answer
2k views
Starting Directory for Bash
I've a Docker container running. I connect to the container using a command like: docker exec -it container_name bash This logs in as root at /var/www/html. I want to know why this directory, and how ...
2 votes
3 answers
1k views
Saving the date to actual bash history file
When adding "HISTTIMEFORMAT" to bashrc, the timestamps of when a command was executed are made available when running the "history" command. But the timestamps themselves are not ...
1 vote
3 answers
5k views
Ubuntu 20.04: su command bash-autocomplete stopped working
I am using Ubuntu 20.04. The su autocomplete stopped working. For example when I type: su TabTab It lists the files and directories of the current directory, where as it should list the available ...
1 vote
1 answer
3k views
How to set a command alias that will be respected in a shebang
I run multiple versions of PHP on my Linux server. I've added an alias in my bashrc to point the php command to a specific version alias php='/usr/bin/php7.3'. This works as expected when I execute a ...
0 votes
0 answers
100 views
Custom bash prompt failing when home directory is remote
0 I am trying to configure a custom prompt for RHEL 8 users. It works very nice when the users have local home directories. However, I'm mounting home directories via pam_mount (nfs4). When ssh'ing to ...
0 votes
1 answer
454 views
Exclude or Include certain profile lines during a tmux session start
In my .bash_profile, I have a line to start tmux only if it is present on the system with: [ -z $TMUX ] && export TERM=xterm-256color && exec tmux In a similar vein, I would like to ...
0 votes
1 answer
403 views
assigning aliases in .bashrc via echo '...' >> .bashrc
running cat .bashrc gives me these two lines at the end: alias remove='rm -i' alias chamber='ls -a -i -l' when I run remove followed by a file name I get a successful removal with confirmation ...
0 votes
2 answers
2k views
Global use of 'aliases' on Debian 10
I've been trying to add global use of aliases on my Debian 10 instance with no luck. What I've already attempted is adding my aliases to /etc/bash.bashrc as well as adding this snippet to /etc/profile ...
0 votes
1 answer
305 views
Aliasing Server Name in SSH Command [closed]
This may be trivial, but I am not sure how do it safely and optimally. I have a few servers (AWS EC2) into which I ssh from the bash. Those server names are long. How can I alias them, so instead of ...
0 votes
0 answers
110 views
/etc/profile, /etc/bash.basrc, ~/.profile, ~/.bashrc are not read
I am a running "Ubuntu 16.04.6 LTS" Linux. I've installed/upgrade some packages, but i do not remember exactly which packages. Since this operation, i have lost ls coloration for all users ...
2 votes
0 answers
211 views
How to auto init direnv on Google Cloud Shell?
my .bashrc has these lines at the bottom: if [ -f $HOME/tools/bashrc ]; then source $HOME/tools/bashrc fi and $HOME/tools/bashrc has this code at the bottom: eval "$(pyenv init -)" pyenv ...
1 vote
1 answer
897 views
Global Bash Completion Scripts
I have a Bash completion script. Is there a place I can put it on my system, so that it will be automatically source-ed for any user that uses a Bash shell? I would prefer a solution that does not ...
0 votes
2 answers
396 views
How to rename system commands e.g., shutdown in Ubuntu Linux
While working on redis server, I come to know there is an option to rename you scracy command to avoid accidental update. Is there any option for bash i.e., Ubuntu Linux especially shutdown, rm and ...
25 votes
3 answers
35k views
~/.bashrc is NOT sourced on ssh 'command'
At the end of .bashrc I added: touch /tmp/bash_noninteractive_test Run: /usr/bin/ssh -v -C [email protected] 'ls' On the host (logged in interactively before): % ls -l /tmp/bash_noninteractive_test ...
2 votes
2 answers
3k views
Displaying complete host name when login to linux
How can I display hostname along with user when I login to Linux machine? Now I can see only part of host name where I could not able to identify the server name. would like to display as below; For ...
0 votes
1 answer
61 views
Source bash.rc / aliasses from external file (LEMP)
I'm running several LEMP VMs with mostly identical setups. Each of these VMs has a /etc/profile.d/00-aliases.sh containing a bunch of aliasses and functions to run on the server. Now, whenever I make ...
1 vote
0 answers
96 views
How to tell screen use use different bash_profile?
How can I tell to screen to use different bash_profile? Problem is we use a technical user to log in, but I edited a custom PS1. Normally I login with putty like: ssh user@host -t "bash --rcfile ~/....
2 votes
3 answers
606 views
Bash commands not found after syntax error
I'm running into an issue where running common bash commands (e.g. ls, mv, rsync, vi) on an Ubuntu 14.04.5 LTS results in something like this: bash: rsync: command not found. When I ssh in I get ...
1 vote
1 answer
2k views
How can I apply "shopt -s extdebug" to my shell by default?
I am trying to build a pre-exec checker in bash (using bash-preexec.sh) In order to fail the command when the pre-exec hook fails, I need to run shopt -s extdebug (which fails the command when trap ...
5 votes
1 answer
8k views
Scripts in /etc/profile.d are being executed twice on login
Background Info: I am trying to configure a Linux server running CentOS 7 for multiple users. After installing java I want to globally set the $JAVA_HOME environment variable for all users and add it ...
1 vote
0 answers
34 views
Linux environment variable setting issue in cluster from single point
I have a cluster of few machines. I have to control all configuration from single system. For that I have decided to used .bashrc in Centos 7 servers (I push same .bashrc in each system via rsync from ...
5 votes
2 answers
11k views
ansible-playbook not able to use .bashrc env variables
I'm using ansible-playbook to deploy my django application to Ubuntu servers. I'm storing my django environment variables in .bashrc file of the user ubuntu in the server. But my ansible-playbook is ...
0 votes
2 answers
332 views
How to export a file to another user's bash while logging in via SSH (using Putty) to RHEL?
I am running RHEL 7.3, however the procedure may be similar on other Linux systems. I have logged in as root. I have a file called openrc which is full of lines like export OS_IDENTITY_API_VERSION=3....
10 votes
5 answers
33k views
Where does the bash PATH on CentOS 7 get /usr/local/bin from?
I've just spun up a brand new CentOS 7 VM (bash version 4.2.46) with Vagrant using the centos/7 box, and when I'm logged in as the vagrant user, this is my PATH: /usr/local/bin:/usr/bin:/usr/local/...
0 votes
3 answers
753 views
Enable confirmation for commands with force flag
Is there any option to enable confirmation for the rm -rf . We had an alias setup for rm=rm -i so whenever we delete a file it asks for confirmation but when -f flag is supplied it will not asks for ...
2 votes
2 answers
97 views
Convenient date/time stamping console interaction e.g. using shell aliases?
So, I often find that I really want to know when I started a process (or script) after I discovered that it was taking ages.. meaning I couldn't pre-pend date before and after it on the command line (...
1 vote
1 answer
375 views
Logout user if they break a bashrc command
I'm running a small script when a user accesses my Linux host via SSH. This script should verify and/or set up Google Authenticator MFA access for the user. Right now it works as intended with one ...
4 votes
2 answers
16k views
Running a bash script from systemd as if I logged in
I have a service implemented as a Bash script. Inside it's actually a node.js application, but it could be anything for the purposes of this question. The basic use case is that we develop/debug the ...
1 vote
2 answers
2k views
'source .bash_profile' fails but 'source path/to/.bash_profile' works
I am trying to source my .bashrc file on remote host inside sudo-less user. I am getting following responses. sh-4.2$ source .bash_profile sh-4.2$ source: .bash_profile: file not found sh-4.2$ ...
2 votes
1 answer
67 views
How to define envrionment variables accesisble by crontab's run and bash shell
I want to define environment variables in one place which will be accessible through different user's crontabs, and from bash shell running. How can I write it once in one place to be accessible to ...
1 vote
0 answers
673 views
Why my profile looks for /usr/local/etc/profile.global (NIS)
My Ubuntu ID is manged by NIS/yellowpage. For some reason, when I log in, I'm getting this message. cat@local:~$ ssh catserver cat@catserver's password: Welcome to Ubuntu 15.10 (GNU/Linux 4.2.0-25-...
2 votes
2 answers
195 views
printing user of subshell obtaining root via su -
Can I print the username which is obtaining root access via su - on the root console upon obtaining root? user1$ su - password: obtained root via user1 #
10 votes
4 answers
15k views
bashrc not loaded in /bin/bash shell
When I ssh into a server (4.3.3-2-ARCH), my .bashrc is not loaded (however, I can load it manually by sourcing it). I don't have any other files in my home folder, like .profile. The shell is also ...
1 vote
3 answers
400 views
Best Practice to obscure path to keypair in bash_profile?
I have dotfiles saved in a public github repo, which include the path to my aws keys, which seems like a terrible thing waiting to happen. So it's like this: function superssh { ssh user@something -...
0 votes
3 answers
2k views
RBASH how to prevent users exiting to normal bash?
I have set up some test account to beta implement rbash to limit users from doing to much on the server. Currently I am using .bash_profile to set bash -r for these profiles. But when a user types ...
3 votes
1 answer
5k views
Can't use functions exported from .bashrc in a bash script
My .bashrc file exports a function called lookup: lookup() { grep -r -ne "$1" * | grep -v "TAGS:" | grep -v "tags:" } export -f lookup I can use that function in a shell. But if I put it in a ...
2 votes
2 answers
617 views
Setting systemwide environment variables which are read when a shell is started
What's the preferred way to set environment variables for all users (on Ubuntu) such that the new variables are read whenever a new shell/terminal is started? Presently, we're using a file in /etc/...
7 votes
1 answer
1k views
How to protect from dangerous bash commands? [closed]
When using bash with or without sudo there are many traps. For example when logged in as root between rm -rf ~/bin and rm -rf /bin there is just one character but this difference can make you ...
2 votes
2 answers
2k views
User created with useradd instead of adduser loads a wrong Prompt
I've designed my bash prompt like this \u@\h> When i now create the User example with adduser, my prompt looks like example@host> But when i create a User with useradd, my prompt looks like \u@\...
0 votes
0 answers
353 views
Sudoers, allow user to use root alias
Actually, my root have to aliases: alias unpool='/path/to/my/scripts/unpool.sh' alias pool='/path/to/my/scripts/pool.sh' I have the same for my user in ~/.bashrc I defined my /etc/sudoers.d/user ...
81 votes
8 answers
161k views
Straight forward way to run ssh-agent and ssh-add on login via SSH?
I'm trying to have the following commands be auto-executed when I login to my server via ssh: ssh-agent /bin/bash ssh-add ~/.ssh/id_rsa My ssh key has a passphrase and I'm fine with entering it once ...
1 vote
1 answer
579 views
Should I be adding aliases to /etc/profile instead of /etc/basrhc?
I've been adding them to /etc/basrhc, and that works most of the time. But I noticed that when I su to another user, I lose all my aliases. It turns out that /etc/bashrc is only loaded when the ...
0 votes
1 answer
832 views
Bashrc function called ssh doesn't work
I created a function in my bashrc file so that when i ssh into something it automatically opens a tmux session. function ssht () { /usr/bin/ssh $@ -t 'tmux a || tmux || /bin/bash' } This ...