LoginSignup
0
0

More than 1 year has passed since last update.

.bashrcにexitと書く

Posted at

.bashrcにexitと書く

linuxでbashを用いているユーザーならみんながお世話になるであろう.bashrc(bashの設定ファイル), これはbashを起動した際に一番最初に実行されるコマンド群が記載されている.

この.bashrcの一行目にexitと書くとすぐにログアウトされることになるだろうというのは想像がつくだろうが試したことはなかった.

これを試してみようとして研究室のウェブサーバーの.bashrcの一行目にexitと書いてみた(書いてしまった).

当初の予定

  1. exitが記載されているとsshログインしたときにすぐにログアウトされることを確認する.
  2. sftpコマンドなどで.bashrcをダウンロードして編集し, 編集したもので上書きする.
  3. 再度ログインできるようになる.

実際の作業

当初の予定の1までは正しく実行できた.

herohero@LOCAL:~$ ssh hogehoge@WEBSERVER
herohero@WEBSERVER's password:
Linux orange 4.9.0-19-amd64 #1 SMP Debian 4.9.320-2 (2022-06-30) x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Fri Jul  8 15:45:28 2022 from 133.87.45.154
Connection to www closed.

ちゃんとログインプロセスが走り, そのあとに入力受付をする前にexitコマンドが走ることでログアウトされている.
その後, 問題は.bashrcの編集にて起きた.

手元のPCから

$ ssh hogehoge@WEBSERVER mv .bashrc bashrc

を実行し, 再度ログインをしようとしたら

herohero@LOCAL:~$ ssh hogehoge@WEBSERVER
herohero@WEBSERVER's password:
Linux orange 4.9.0-19-amd64 #1 SMP Debian 4.9.320-2 (2022-06-30) x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Fri Jul  8 15:45:28 2022 from 133.87.45.154
Connection to www closed.

またこれが出てしまう.
そのため, sftp を実行し, .bashrcをダウンロードしてから編集して再度アップロードをしようと試みるも……

herohero@LOCAL:~$ sftp hogehoge@WEBSERVER
hogehoge@WEBSERVER's password:
Connection closed
herohero@LOCAL:~$

となった.

どうやら, .bashrcはsftpにも作用しているらしい.

禁断のscpコマンドを実行しようとしたところ(よいこはマネしないでね!!!)

herohero@LOCAL:~$ scp hogehoge@WEBSERVER:.bashrc ./
herohero@WEBSERVER's password:
herohero@LOCAL:~$

となり, これも上手くいかない.

結局にっちもさっちもいかなくなって研究室のwebserver管理者に依頼して.bashrcの一行目からexitを削除してもらいました.

結論

  1. .bashrcはsshだけでなく, sftpにも作用する.
  2. .bashrcにexitと書くとログインできなくなる(ログインはするけれど即座にログアウトされる)
  3. 管理者に依頼してexitを削除してもらわねばならない.
  4. sshでこれを実行するときは.bashrcを編集するターミナルとログインを試すターミナルを分けよう.
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0