Skip to main content
14 events
when toggle format what by license comment
Feb 1, 2023 at 0:49 comment added xeruf self answer: check shell interactivity instead unix.stackexchange.com/questions/26676/…
Jan 29, 2023 at 18:35 comment added xeruf SSH_CONNECTION is also set when using scp, leading to a warning, how could I avoid that?
Jul 4, 2013 at 11:34 comment added Steen Schütt Might be worth noting that you can also put the commands in /etc/profile to run it for any user.
Nov 9, 2011 at 10:15 vote accept Alasdair
Nov 8, 2011 at 7:12 history migrated from stackoverflow.com (revisions)
Nov 8, 2011 at 6:58 comment added dgrant When you run "su - " it provides a "login shell" a shell as if root had logged in directly. I assume this means it will run the .profile/.bash_profile/.bashrc scripts for root, and remove any of the stuff that was set in the user's .profile/.bash_profile/.bashrc. I haven't used "su - " before, but people use it a lot, and that's what the man page implies it does.
Nov 8, 2011 at 6:55 comment added dgrant let us continue this discussion in chat
Nov 8, 2011 at 6:54 comment added dgrant First of all, I would recommend putting "sudo" in front of commands that require it, rather than switching to root.
Nov 8, 2011 at 6:52 comment added dgrant NOTE: actually, it's .profile that gets called if it exists, unless .bash_profile, exists, then it is called instead.
Nov 8, 2011 at 6:52 comment added Alasdair Also, since I am changing user, I expect that in the ec2-user bash profile I should put only "sudo su -", and then the rest of the commands in the root bash file?
Nov 8, 2011 at 6:52 comment added Alasdair You've confused me, let me explain more: This is an Amazon Web Services instance, which is a virtually server, so no one will ever physically log in (I'm not even sure if it physically exists as one machine). I login using PUTTY with the username ec2-user. This drops me in /home/ec2-user directory. I then change to root user by typing "sudo su -", which then drops me into "/root", then I have to type a series of commands, including changing me back to "/home/ec2-user" and setting some variables, aliases, etc. So... how would I get it to do this?
Nov 8, 2011 at 6:46 comment added dgrant This assumes ~/.bashrc is sourced from your ~/.bash_profile. ~/.bash_profile will be the script that is invoked for a login shell like ssh. I believe ~/.bashrc will get called if you open up a Gnome Terminal, for example, AFTER having already logged in.
Nov 8, 2011 at 6:45 comment added Alasdair I'm not logging in as root, it's an AWS server so I have to login as "ec2-user" then change to root using "sudo su -". So should I put the commands in "/home/ec2-user/.bashrc"?
Nov 8, 2011 at 6:41 history answered David Z CC BY-SA 3.0