Answer the question
In order to leave comments, you need to log in
How to execute a command on the server when connected via ssh?
Good afternoon, colleagues.
When connecting to some servers, the first thing I do is run the command
sudo screen -xR admin_name -c /root/.screenrc_admin_name
to use my screen config, which already pulls up my bashrc and so that my config doesn't get in the way of my co-workers. This is not very convenient. Enter every timessh server1 "sudo screen -xR admin_name -c /root/.screenrc_admin_name"
I also don't want to. I would like to make this command run automatically. But here's how to implement it? command="sudo screen -xR admin_name -c /root/.screenrc_admin_name" ssh-rsa ....
not suitable, because after that scp stops working, etc. Yes, and it is inconvenient if there are a lot of servers. alias server23='ssh [email protected] "sudo screen -xR admin_name -c /root/.screenrc_admin_name"'
Also not an option. Personally, it's not convenient for me to enter just the server name. Get into the habit of writing "ssh server1" (all servers are in ~/.ssh/config). ssh() {
ssh "$1" -F ~/.ssh/config "sudo screen -xR admin_name -c /root/.screenrc_admin_name"
}
This is an option. At the moment it has been done. Answer the question
In order to leave comments, you need to log in
In principle, you can try to add a check to the client's IP in .bashrc, since you always log in from your computer.
Take the $SSH_CLIENT variable, cut off the first column, compare it with the IP of your computer. If it matches, then it was you who connected, and you can turn on your configs.
CLIENT_IP="${SSH_CLIENT%% *}"
if ; then
source ~/.bashrc_Angel2S2
fi
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question