Re:Run Commands, the 'rc' in '.bashrc'
by aidos on Sunday September 01, 2019 @02:26PM
(#20853816)
More interestingly, I only recently learned that you can add a ~/.ssh/rc to run commands on every ssh login. Are there other common useful rc locations people are aware of?
[ Parent
| on HN ]
Re:Run Commands, the 'rc' in '.bashrc'
by jeremyjh on Sunday September 01, 2019 @06:22PM
(#20855405)
Can anyone give an example of a command I'd want to run on every .ssh login, but not put into my .zshrc/.bashrc on that machine?
Re:Run Commands, the 'rc' in '.bashrc'
by syncsynchalt on Sunday September 01, 2019 @06:33PM
(#20855456)
As an example: I'd love to run `set -o vi` on every ec2-user login, but the machines tend to be ephemeral and this command might not be wanted by other users, so I don't add it to /etc/profile or /etc/bashrc.
Re:Run Commands, the 'rc' in '.bashrc'
by jeremyjh on Sunday September 01, 2019 @10:05PM
(#20856268)
Why wouldn't you put that in ~/.bashrc ?
Re:Run Commands, the 'rc' in '.bashrc'
by syncsynchalt on Monday September 02, 2019 @05:23PM
(#20861866)
The ec2-user is shared by all users who might login; our EC2 hosts usually only last a few minutes/hours and are only accessed during debugging or extraordinary circumstances.
Re:Run Commands, the 'rc' in '.bashrc'
by jeremyjh on Monday September 02, 2019 @06:56PM
(#20862320)
The .ssh/rc file goes on the server though, so you’d still have that problem.
What if you don't have a home directory on an ephemeral server?
Then you won’t have anywhere to store ~/.ssh/rc, and the version you’d put in /etc would still unfortunately apply to all users.
Your ssh rc is stored locally, to be executed on remote servers, right? Locally you have a home dir, but you don't on the remote.
No, it lives on the server.
allows you to use vi on the command line for anyone else who was wondering.
okay? If i'm wrong, what's it for?
Re:Run Commands, the 'rc' in '.bashrc'
by mikekchar on Monday September 02, 2019 @01:28AM
(#20856954)
It could be worded better. It allows you to use vi style keybindings when editing a line in bash. By default bash uses emacs style keybindings. It doesn't actually use vi.
thanks.
Re:Run Commands, the 'rc' in '.bashrc'
by scardine on Sunday September 01, 2019 @10:36PM
(#20856383)
If you run a terminal multiplexer like byobu you may want to run it only for the ssh connection, not for every sub-shell (otherwise you may get a warning about running a multiplexer inside another multiplexer session).
Re:Run Commands, the 'rc' in '.bashrc'
by AdamGibbins on Sunday September 01, 2019 @07:14PM
(#20855608)
`w` on multi-user machines that you're logging into to debug, so you can see who's on it and when they were last active.
Re:Run Commands, the 'rc' in '.bashrc'
by marcosdumay on Monday September 02, 2019 @10:49AM
(#20859403)
You can automatically (re)start tmux so your sessions survive losing a connection.
Re:Run Commands, the 'rc' in '.bashrc'
by 713233eb on Monday September 02, 2019 @12:04AM
(#20856700)
You might want to curl the weather on your login with https://github.com/chubin/wttr.in I do this on my RPi
Starting a multiplexer
Notifications from sysadmin to user, reminders, and that sort of thing.
Re:Run Commands, the 'rc' in '.bashrc'
by jlgaddis on Monday September 02, 2019 @03:33AM
(#20857378)
That's what /etc/motd was intended for
motd is not a per-user dynamic output though unless you put together some interesting hacks.
Re:Run Commands, the 'rc' in '.bashrc'
by boobePhuu7iet7i on Sunday September 01, 2019 @05:48PM
(#20855188)
Do you add that on your system, and it executes the commands on all the servers you connect to?
Or do you add it to the server and they only run when you login to that server?
Looks like it executes the commands only on the server where
~/.ssh/rc or /etc/ssh/sshrc exists.
> ~/.ssh/rc
> Commands in this file are executed by ssh when the user logs in, just before the user's shell (or command) is started. See the sshd(8) manual page for more information.
You add it to the remote system.
I use it for updating a symlink in a known location to point to SSH_AUTH_SOCK. I then get tmux sessions set up to look in that location. Effectively, each time I ssh in, I fix all the ssh forwarding in active sessions (this is on local dev vagrant machines).