You are currently viewing su, su -, sudo -i, sudo -s arasındaki farklar nedir?

su, su -, sudo -i, sudo -s arasındaki farklar nedir?

Sunucuda root olmak için genellikle su – komutunu kullandım. Neden öyle? Aslında, bu sadece bir alışkanlık. Yani, üniversite zamanlarımdan kalma. Okuduğum Unix/Linux kitaplarında ve eğitmenlerimde hep su – komutunun kullanıldığını gördüğüm için; bende de bu şekilde alışkanlık edinmiş diyebilirim. Hatta sudo komutunu Ubuntu 4.10’da ilk orada görmüştüm ve şaşırmıştım. 😀

sudo -s vs sudo -i

Man sayfasını kontrol edersek:

-s, — shell Run the shell specified by the SHELL environment variable if it is set or the shell specified by the invoking user’s password database entry. If a command is specified, it is passed to the shell for execution via the shell’s -c option. If no command is specified, an interactive shell is executed.

Bu, bir dizini değiştirmeden kabuğu root’tan çalıştırdığımız anlamına gelir, ayrıca env değişkenleri (.bash_profile veya .login’de ayarlanabilen) içe aktarılmaz.

Ancak sudo -i komutuyla başka bir durumumuz var:

-i, — login Run the shell specified by the target user’s password database entry as a login shell. This means that login-specific resource files such as .profile or .login will be read by the shell. If a command is specified, it is passed to the shell for execution via the shell’s -c option. If no command is specified, an interactive shell is executed. sudo attempts to change to that user’s home directory before running the shell. The command is run with an environment similar to the one a user would receive at log in. The Command environment section in the sudoers(5) manual documents how the -i option affects the environment in which a command is run when the sudoers policy is in use.

Burada env değişkenlerini de içe aktardığımızı ve dizini değiştirdiğimizi görüyoruz. Bu yüzden sudo -s yerine sudo -i komutunu kullanmaya başlayabilirsiniz.

su vs su –

su ve su – durumunda da önemli farklar var.

su komutu env değişkenlerini temizlemez, sadece bir kullanıcıyı root olarak değiştirir ve env değişkenlerini eski kullanıcı için tutar.

su - komutunda ise ilk iş kullanıcıyı değiştirmektir ve ondan sonra yeni bir kabuk çalıştırmaktır. Bu, tüm env değişkenlerinin temizlendiği ve “temiz” root oturumunun yürütüldüğü anlamına gelir.

İşte bu kadar basit.