So laden Sie Teile des bash-Alias ​​nur, wenn Sie sich über ssh anmelden

343
jrmo14

Wie der Titel besagt, ist es möglich, einen Alias ​​nur zu laden, wenn ich über ssheinen Computer oder besser noch über einen bestimmten Computer auf den Computer zugreife ssh?

5

2 Antworten auf die Frage

7
Jakuje

In .bashrc(oder wo Sie die Aliase definieren) können Sie die Bedingung abhängig von der Variablen machen SSH_CONNECTION, die nur für ssh-Verbindungen festgelegt ist. Zum Beispiel:

if [[ $SSH_CONNECTION == *"your-IP"* ]]; then alias ll="ls -l" # your other aliases fi 
Gibt es eine Möglichkeit, die MAC-Adresse und nicht die IP-Adresse zu überprüfen? Oder ist das eine schlechte Praxis? jrmo14 vor 6 Jahren 0
Nein, es ist nicht möglich, es sei denn, Sie konfigurieren die Clients so, dass sie auch den MAC senden. Die Identifizierung per Mac ist keine gute Idee., Jakuje vor 6 Jahren 1
0
Nagaraj Nookala

As i interpret your question, when you ssh to a linux box with an user other than root, the logged in user should have only limited access to the commands and you also want aliases to that commands. The possible solution is

  1. Create a restricted shell by copying bash file in /bin directory cp /bin/bash /bin/rbash
  2. Modify the user bash to the restricted bash useradd -s /bin/rbash, in case of existing user usermod -s /bin/rbash . After this the user will be able to access only his home directory.
  3. Create a directory under /home//commands
  4. Now to restrict the access of the commands add the following lines to /home//.bash_profile file PATH=$HOME/commands export PATH
  5. Create softlinks to the commands in /home//commands folder which you want to give permission to the user e.g: ln -s /bin/date /home//commands/
  6. As logged in user can modify the /home//.bash_profile you have to make it immutable so that user cannot access it. chattr +i /home//.bash_profile
Sorry, ich wollte die Berechtigungen eines Benutzers zur Verwendung eines Alias ​​nicht einschränken. Der Zweck war, tmux -CC als tmux alias zu machen, wenn ich mich über ssh anmelde. Danke für die Antwort, ich wusste nicht, dass das möglich ist. jrmo14 vor 6 Jahren 0