Questions tagged [bashrc]

The Bashrc file is used by the Bourne Again Shell in Unix/Linux to set environment variables and run commands.

Filter by
Sorted by
Tagged with
4 votes
1 answer
7k 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 ...
0 votes
1 answer
69 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 ...
1 vote
1 answer
67 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
733 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 ...
71 votes
6 answers
113k 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 ...
0 votes
2 answers
415 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 ...
21 votes
2 answers
25k 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
1 answer
1k 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, ...
29 votes
6 answers
34k views

How to use a custom .bashrc file on SSH login

I've found that with the new company I'm working with I often have to access linux servers with relatively short lifetimes. On each of these servers I have an account, but whenever a new one is ...
4 votes
3 answers
2k views

exporting bashrc file over an ssh connection

I have my bashrc file set up to my liking.I usually work on a hardware that is plugged into a remote server.I ssh into that remote server.I would like my .bashrc to be run when I ssh into the remote ...
0 votes
1 answer
670 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 ...
113 votes
21 answers
170k views

Login without running bash_profile or bashrc

So let's say one typoed something in their .bashrc that prevents him (or her) from logging in via ssh (i.e. the ssh login exits because of the error in the file). Is there any way that person could ...
1 vote
3 answers
3k 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
1k 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 ...
1 vote
3 answers
871 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 ...
4 votes
2 answers
14k 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 ...
0 votes
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 ...
9 votes
5 answers
31k 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
0 answers
81 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
279 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
312 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 ...
4 votes
2 answers
10k 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 ...
2 votes
4 answers
3k views

GNU Screen and .bashrc

I am trying to launch GNU Screen using my .bashrc. I'm almost there: if [ -z "$STY" ]; then exec screen -dR else exec gnome-terminal fi This is wrong though! The first case works, screen ...
0 votes
2 answers
1k 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
274 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
82 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 ...
92 votes
6 answers
55k views

Standard place for user defined bash_completion.d scripts?

I have user access (no root) into a Linux (Suse) machine where I developed some bash scripts and the corresponding bash autocompletion rules. Since the scripts belong only to my user and therefore I ...
31 votes
10 answers
20k views

I screwed up, exit in .bashrc

I put "exit" in my .bashrc file. I don't have physical access to the machine so to connect to it I use ssh. I don't have root privileges. Every time I connect to the server, the connection ...
2 votes
0 answers
168 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
582 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 ...
23 votes
6 answers
16k views

Use .bashrc without breaking sftp

My problem is that I need to set a few variables, and output a few lines every time I login to the ssh shell, and at the same time I have to be able to use sftp to tarnsfer files via Filezilla. Now, ...
9 votes
5 answers
22k views

How do I restore the default bashrc?

I have accidentally overwritten .bashrc. I did the following echo 'export EDITOR=/usr/bin/nano' >> /etc/bashrc Bur I accidentally typed > instead of >>. I guess, it was a bad idea. I ...
0 votes
2 answers
260 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 ...
8 votes
4 answers
12k 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 ...
2 votes
2 answers
2k 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
51 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 ...
11 votes
3 answers
42k views

.bashrc: shopt: not found

Just provisioned a new Rackspace instance with Ubuntu 12.04 and pulled down rbenv from their github and installed it. I'm getting the following errors when executing . ./~bashrc $ . ~/.bashrc sh: 18:...
1 vote
0 answers
76 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
2 answers
622 views

Added line to bashrc, now bash is not responding

I added the following line to the end of my ~/.bashrc (This is on a Linode box) and logged out of my ssh session. source ~/.profile Now when I log in, the shell is unresponsive. I never get to the ...
2 votes
3 answers
500 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
1k 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 ...
1 vote
0 answers
27 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 ...
0 votes
2 answers
273 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....
0 votes
3 answers
630 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
66 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
322 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 ...
1 vote
2 answers
1k 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
59 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
616 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
158 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 #