Hot answers tagged

74 votes

Standard place for user defined bash_completion.d scripts?

For non-XDG environments and bash-completion <= 2.8 Here is how a local user can have a working ~/.bash_completion.d/ directory. edit file: nano ~/.bash_completion, add the following: for bcfile ...
user avatar
72 votes
Accepted

Straight forward way to run ssh-agent and ssh-add on login via SSH?

You can try adding this: eval $(ssh-agent -s) ssh-add ~/.ssh/id_rsa This way the ssh-agent does not start a new shell, it just launches itself in the background and spits out the shell commands to ...
user avatar
  • 1,702
31 votes

Login without running bash_profile or bashrc

You need to a) start bash without source'ing either ~/.bashrc or ~/.bash_profile and b) since such a shell wouldn't be a full login shell / have no tty attached, force ssh to attach a tty: ssh -t ...
user avatar
18 votes
Accepted

bashrc not loaded in /bin/bash shell

the ~/.bashrc file is loaded for interactive non-login shells, that's why running /bin/bash from ssh works as you expect. For login shells (amongst others) ~/.bash_profile is read. Typically your ~/....
user avatar
  • 113k
17 votes

How to use a custom .bashrc file on SSH login

I think sshrc is what you're looking for: https://github.com/Russell91/sshrc sshrc works just like ssh, but it also sources ~/.sshrc after logging in remotely. $ echo "echo welcome" > ~/.sshrc $...
user avatar
15 votes

Where does the bash PATH on CentOS 7 get /usr/local/bin from?

Other people have asked the same thing on the CentOS bug tracker. The earliest post I found was this one. /usr/local/bin is hardcoded in /bin/bash. https://bugs.centos.org/view.php?id=10200 https://...
user avatar
  • 2,870
13 votes

Standard place for user defined bash_completion.d scripts?

The FAQ has been updated. There is now a standard place for local completions. Q. Where should I install my own local completions? A. Put them in the completions subdir of $...
user avatar
  • 251
13 votes
Accepted

How do I restore the default bashrc?

Move the damaged file out of the way, then reinstall the package that provides the damaged file. mv /etc/bashrc /etc/bashrc.damaged yum reinstall $(rpm -qf /etc/bashrc)
user avatar
11 votes

How to protect from dangerous bash commands?

First off, never use root to execute day-to-day commands. That's the best way to actually expose yourself to disasters. With that in mind, if you use sudo, you can actually limit commands AND the ...
user avatar
  • 3,079
10 votes

How do I restore the default bashrc?

Did you overwrite the .bashrc in your user directory? Or the systemwide .bashrc stored in /etc/skel/? You can always copy the default.bashrcfrom/etc/skel/` like this: cp /etc/skel/.bashrc ~/.bashrc ...
user avatar
  • 3,512
8 votes
Accepted

Where does the bash PATH on CentOS 7 get /usr/local/bin from?

In the bash source "config-top.h" has this: /* The default value of the PATH variable. */ #ifndef DEFAULT_PATH_VALUE #define DEFAULT_PATH_VALUE \ "/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/...
user avatar
  • 787
7 votes
Accepted

Can't use functions exported from .bashrc in a bash script

Check http://www.gnu.org/software/bash/manual/bashref.html#Bash-Startup-Files Invoked non-interactively When Bash is started non-interactively, to run a shell script, for example, it looks for ...
user avatar
7 votes

Best Practice to obscure path to keypair in bash_profile?

Hiding your key in an unusual place is not making it any safer. If you undertake basic good practice for key management there's really no need to do anything extra. Your private key needs to be kept ...
user avatar
  • 113k
6 votes

Login without running bash_profile or bashrc

None of the above answers can bypass the login shell of ssh. You can pass a full command line, and so it runs the remote shell to process the command and set the working environment for the command. ...
user avatar
6 votes

Standard place for user defined bash_completion.d scripts?

At least bash-completion 2.8 and later enable option to place local Bash completions in directory ${BASH_COMPLETION_USER_DIR:-${XDG_DATA_HOME:-$HOME/.local/share}/bash-completion}/completions The ...
user avatar
  • 163
6 votes

Straight forward way to run ssh-agent and ssh-add on login via SSH?

One alternative is to use Funtoo's Keychain. Then you can stick this one-liner in your bash shell: eval $(keychain --eval id_rsa) That does the same thing (launches ssh agent, etc.), while also not ...
user avatar
6 votes

Where does the bash PATH on CentOS 7 get /usr/local/bin from?

It definitely looks hard coded into /bin/bash strings /bin/bash | grep "\/usr\/local\/bin" /usr/local/bin:/bin:/usr/bin which seems to be the default PATH.
user avatar
  • 113k
6 votes
Accepted

~/.bashrc is NOT sourced on ssh 'command'

From the INVOCATION chapter of man bash: When an interactive shell that is not a login shell is started, bash reads and executes commands from /etc/bash.bashrc and ~/.bashrc, if these files exist. ...
user avatar
  • 4,043
5 votes

Straight forward way to run ssh-agent and ssh-add on login via SSH?

Another alternative is to add this to your .bashrc. This has the same advantage as Erik's answer (ensuring a single instance) but doesn't require an additional package. # SSH Agent should be running, ...
user avatar
5 votes
Accepted

'source .bash_profile' fails but 'source path/to/.bash_profile' works

You are using bash in POSIX mode. From man bash under source filename [arguments] If filename does not contain a slash, file names in PATH are used to find the directory containing filename... ...
user avatar
  • 19.2k
5 votes

Where does the bash PATH on CentOS 7 get /usr/local/bin from?

In addition to previous answers; If you are reaching you VM by ssh this could has sense. In /etc/ssh/sshd_config: # This sshd was compiled with PATH=/usr/local/bin:/usr/bin
user avatar
  • 276
5 votes
Accepted

Aliasing Server Name in SSH Command

This should work: create a file $HOME/.ssh/config (or in /etc/ssh/ssh_config, if you want to install that alias system-wide), and put the following config inside: Host myalias Hostname very-long-...
user avatar
  • 1,783
4 votes

Standard place for user defined bash_completion.d scripts?

A simpler solution is to use the nullglob option. While this isn't portable, neither are bash completions. So portability doesn't matter. Also, you'll want to use quotes around the variable when ...
user avatar
4 votes
Accepted

Bashrc function called ssh doesn't work

SSH Bash Function Making an ssh function to run something on login like you did, you can do the following: function ssht () { \ssh $@ -t 'tmux a || tmux || /bin/bash' } alias ssh=ssht ...
user avatar
  • 5,170
4 votes

Convenient date/time stamping console interaction e.g. using shell aliases?

You can simply modify your shell prompt PS1 variable to show current timestamp. One of the following can be used: \t the current time in 24-hour HH:MM:SS format \T the current time in 12-hour ...
user avatar
  • 35.4k
4 votes

~/.bashrc is NOT sourced on ssh 'command'

Adding my bit to the old thread for information because the accepted answer is not the real reason for .bashrc not being read for an ssh command. I got the hint after reading this answer. The second ...
user avatar
3 votes

Login without running bash_profile or bashrc

ssh -t user@host "bash --norc --noprofile -c '/bin/rm .bashrc'"
user avatar
  • 131
3 votes
Accepted

Where is this bash shell alias being configured?

If all your users have .bashrc with a reference to execute /etc/bashrc, then adding a line at the bottom of that file would be a good place to make this modification overwriting the previous alias. ...
user avatar
  • 705
3 votes

Best Practice to obscure path to keypair in bash_profile?

If someone has enough access to your box to harvest your keys, it's game over anyway. Don't worry about it.
user avatar
  • 108k
3 votes

How to define envrionment variables accesisble by crontab's run and bash shell

I don't think you can do this in the crontab directly. The crontab file isn't a shell script so trying to source a script containing envvars into it doesn't work . /path/to/envvars crontab won't ...
user avatar
  • 113k

Only top scored, non community-wiki answers of a minimum length are eligible