![](/img/trans.png)
[英]When executing an SSH command in Jenkins, the bash profile is different to when connecting over SSH with the same user
[英]Prevent .bash_profile from executing when connecting via SSH
我有幾台服務器運行 Ubuntu 18.04.3 LTS。 盡管自動登錄被認為是不好的做法,但我理解其中的風險。
我已執行以下操作來自動登錄用戶:
sudo mkdir /etc/systemd/system/getty@tty1.service.d
sudo nano /etc/systemd/system/getty@tty1.service.d/override.conf
然后我將以下內容添加到文件中:
[Service]
ExecStart=
ExecStart=-/sbin/agetty --noissue --autologin my_user %I $TERM
Type=idle
然后,我編輯以下文件,以便用戶能夠自動啟動程序:
sudo nano /home/my_user/.bash_profile
# Add this to the file:
cd /home/my_user/my_program
sudo ./program
當服務器啟動時,這在控制台上效果很好,但是,當我 SSH 進入服務器時,啟動了相同的程序,我不希望這樣。
最簡單的解決方案是 SSH 與不同的用戶,但有沒有辦法阻止程序運行時我 SSH 在使用相同的用戶?
簡單的方法是檢查變量 ssh 設置的環境; 有幾個。
# only run my_program on login if not connecting via ssh
if [ -z "$SSH_CLIENT" ]; then
cd /home/my_user/my_program && sudo ./program
fi
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.