- Как определить и изменить командную оболочку (shell) в Linux
- Что такое командная оболочка
- Оболочки Linux
- Как определить текущую командую оболочку
- Способ 1
- Способ 2
- Способ 3
- Как посмотреть список оболочек, доступных в системе
- Как временно переключиться на другую оболочку
- Как изменить оболочку
- Заключение
- Change my default shell in Linux using chsh
- How to Change my default shell
- List your shells in Linux
- Find out your current shell name
- Changing default shell from bash to ksh
- Changing back your shell to bash with chsh
- Getting help about the chsh command
- Conclusion
- How To Change Shell To Bash in Linux / Unix
- How do I find out the default shell for a user?
- How do I see what shells are available on my system?
- How do I switch to a bash or different shell?
- How to change shells on a Linux or Unix-like systems?
- Summing up
- How to Change Shell in Linux
- How to know the default shell?
- How to see what shell are you currently using?
- How to see all the shells available on your Linux system?
- How to change the shell to use another one?
- How to change the default shell in Linux permanently?
- How To Change The Default Shell In Linux
- How to change the default login shell using chsh (from the command line)
- Change the shell for your user in a terminal application
Как определить и изменить командную оболочку (shell) в Linux
Что такое командная оболочка
Командная оболочка или командный интерпретатор в Linux — это программа, которая в текстовой среде выступает в качестве интерфейса между пользователем и операционной системой. Она интерпретирует вводимые команды с терминала и вызывает необходимые программы.
Когда вы работаете в терминале, именно командная оболочка обрабатывает вводимые вами команды. Более того, оболочки Linux поддерживают написание программ на языке оболочки.
Оболочки Linux
Одна из самых популярных командных оболочек — это оболочка Bash (Bourne Again Shell). Она используется по умолчанию в большинстве дистрибутивов Linux.
Существуют разные оболочки Linux. Можно отметить:
- bash
- csh
- dash
- fish
- ksh
- pdksh
- rbash
- sh
- tcsh
- zsh
Оболочки могут очень сильно отличаться друг от друга. Они отличаются функциональностью, синтаксисом команд, строкой приветствия, дружелюбностью к пользователю и другими параметрами и возможностями.
Как определить текущую командую оболочку
Есть несколько способов определить оболочку, используемую по умолчанию в вашей системе Linux. Рассмотрим несколько из них, так как в разных системах (и оболочках) какие-то способы могут не сработать.
Также нужно знать, что у разных пользователей системы могут использоваться разные оболочки.
Способ 1
Переменная окружения SHELL хранит путь до исполняемого файла оболочки. Выполним команду:
Из вывода команды, мы видим, что используется оболочка bash.
Способ 2
Также можно воспользоваться командой echo $0 . Данная команда выведет на экран имя текущего работающего процесса, внутри которого она выполнена. Так как мы выполняем команду внутри оболочки, то будет выведено имя оболочки.
Способ 3
Определим, работающий процесс оболочки командой ps.
Как посмотреть список оболочек, доступных в системе
Список оболочек, которые в данный момент установлены и доступны в системе Linux, хранится в файле /etc/shells
Выведем содержимое файла /etc/shells , для этого выполняем команду:
Как временно переключиться на другую оболочку
Чтобы временно переключиться на другую оболочку, достаточно выполнить в терминале команду, соответствующую ее имени. После этого вы переключитесь на новую оболочку.
Например, переключимся на оболочку sh. Выполняем команду:
Как изменить оболочку
Для изменения командной оболочки на постоянной основе служит команда chsh (от слов change shell).
Чтобы изменить оболочку текущего пользователя нужно выполнить команду:
В качестве параметра путь_новой_оболочки необходимо указать путь до исполняемого файла оболочки, который вы можете найти в файле /etc/shells (см. выше).
Например, изменим оболочку на sh. Для этого выполняем команду (при выполнении команды нужно будет ввести пароль):
После этого нужно выйти и снова войти в систему.
Чтобы изменить оболочку, используемую по умолчанию, для другого пользователя, то команде chsh необходимо указать имя этого пользователя:
Заключение
Мы рассмотрели, как определить текущую оболочку Linux, как просмотреть список доступных оболочек, а также как изменить оболочку, используемую по умолчанию.
Чтобы получить информацию о какой-либо оболочке (доступной в системе) можно воспользоваться Man-страницами. Например:
Дополнительные оболочки можно устанавливать средствами системы (из репозиториев). Например, для установки оболочки fish в Ubuntu Linux, выполните команду
Источник
Change my default shell in Linux using chsh
How to Change my default shell
- First, find out the available shells on your Linux box, run cat /etc/shells
- Type chsh and press Enter key
- You need to enter the new shell full path. For example, /bin/ksh
- Log in and log out to verify that your shell changed corretly on Linux operating systems.
Let us see all commands in details.
List your shells in Linux
Run the following cat command on the /etc/shells file:
cat /etc/shells
Of course, we can use the grep command/egrep command to find out if particular shell such as zsh or fish installed or not, run:
grep «zsh» /etc/shells
grep «fish» /etc/shells
- No ads and tracking
- In-depth guides for developers and sysadmins at Opensourceflare✨
- Join my Patreon to support independent content creators and start reading latest guides:
- How to set up Redis sentinel cluster on Ubuntu or Debian Linux
- How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
- How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
- A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
- How to protect Linux against rogue USB devices using USBGuard
Join Patreon ➔
Find out your current shell name
Execute any one of the following command to find the current shell instance:
ps -p $$
OR
printf «My current shell — %s\n» «$SHELL»
OR
grep «^$
Changing default shell from bash to ksh
To change your shell to zsh with chsh, run:
type -a zsh ## find path to ksh ##
chsh -s /bin/zsh ## change bash to ksh ##
Verify it:
grep «^$
Log out and log in again. One can close the Terminal app and reopen it or use the su command as follows”
su — vivek
Changing back your shell to bash with chsh
Want to reverse changes? Try:
type -a bash
chsh -s /bin/bash
## replace vivek with actual username ##
grep ‘^vivek’ /etc/passwd
su — vivek
Getting help about the chsh command
Type any one of the following command at the CLI:
man chsh
OR
chsh —help
The options are as follows:
- -h : Display help message and exit.
- -R CHROOT_DIR : Apply changes in the CHROOT_DIR directory and use the configuration files from the CHROOT_DIR directory.
- -s /path/to/SHELL : The name of the user’s new login shell. Setting this field to blank causes the system to select the default login shell.
Conclusion
You learned about changing your default shell with chsh command. See shadow-utils home page for more info here.
🐧 Get the latest tutorials on Linux, Open Source & DevOps via
Источник
How To Change Shell To Bash in Linux / Unix
H ow do I switch from a ksh shell to bash on Linux or Unix system? How to change shells on Unix-like system?
A shell is nothing but a command that provides a text-only user interface (also known as “command line interface”) for Linux, MacOS, and Unix-like operating systems. Bash shell read commands such as ls, date and others typed into a terminal and then run them. That is the primary function of bash shell.
Tutorial details | |
---|---|
Difficulty level | Easy |
Root privileges | No |
Requirements | Linux or Unix-like OS |
Est. reading time | 2 minutes |
How do I find out the default shell for a user?
Type the following command to find out the default shell for a user named vivek using the grep command and /etc/passwd file:
$ grep vivek /etc/passwd
vivek:x:1005:1005. /home/vivek: /bin/zsh
OR
$ ps -p $$
PID TTY TIME CMD
14314 pts/9 00:00:00 zsh
OR
$ echo $0
zsh
All of the above output indicates that the shell is zsh for user named vivek in Linux operating system.
How do I see what shells are available on my system?
Type the cat command as follows:
$ cat /etc/shells
Fig.01: How to find list of available shells on Linux or Unix or MacOS?
How do I switch to a bash or different shell?
Type the name at the command line and then press the enter key. In this example, to change from any shell to the bash, type:
bash
- No ads and tracking
- In-depth guides for developers and sysadmins at Opensourceflare✨
- Join my Patreon to support independent content creators and start reading latest guides:
- How to set up Redis sentinel cluster on Ubuntu or Debian Linux
- How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
- How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
- A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
- How to protect Linux against rogue USB devices using USBGuard
Join Patreon ➔
How to change shells on a Linux or Unix-like systems?
You can change your default shell using the chsh (“change shell” ) command as follows. The syntax is:
chsh
chsh -s
chsh -s
chsh -s /bin/bash
chsh -s /bin/bash vivek
You can find full path to your shell using the following command:
type -a bash
type -a zsh
type -a ksh
Please note that a normal user may only change the login shell for her own account. The superuser (root) may change the login shell for any account using the following syntax:
$ sudo chsh -s /bin/bash raj
OR use the su command instead of sudo command:
$ su —
# chsh -s /bin/bash monika
Summing up
The only restriction placed on the login shell is that the shell command name must be listed in /etc/shells file, unless the invoker is the superuser/root user, and then any value may be added. An account with a restricted login shell may not change her login shell. For this reason, placing /bin/rsh in /etc/shells is discouraged since accidentally changing to a restricted shell would prevent the user from ever changing her login shell back to its original value.
🐧 Get the latest tutorials on Linux, Open Source & DevOps via
Источник
How to Change Shell in Linux
This quick tutorial shows how to check the running shell, available shell in the system and how to change the default shell in Linux.
You probably are already aware that there are several shell available on Linux and other Unix-like systems. Bash is the default shell on almost all the Linux distributions but there are some other popular shells available such as:
Some of the shells provide additional features in a more user-friendly way. Take Fish shell for example. It partially starts showing you command hints based on your previous typed command. It’s quite handy if you don’t want remember the Linux terminal shortcuts all the time.
Let’s see a few things around shell in your Linux system.
How to know the default shell?
To know the default shell set for you in your Linux system, you can check the SHELL environment variable. Usually, the default shell is bash and it is shown like this:
How to see what shell are you currently using?
There is no single method that will tell you which shell you are using with 100% accuracy.
You can try either echo $0 that shows you an output like this:
or check the process using ps -p $$ like this:
How to see all the shells available on your Linux system?
All the shells available on your Linux systems are listed in the file /etc/shells. You can use cat command or less command to view the content of the file.
How to change the shell to use another one?
If you want to use a different shell, you can simply type its name and you’ll be logged into the new shell. For example, if you install zsh and want to use it, you can simply use:
You can enter exit to exit from the new shell and return to the previous one.
How to change the default shell in Linux permanently?
Suppose you liked the Fish shell a lot and you want to use it as your default shell so that every time you open the terminal or ssh into the system, you are using it instead of the default bash shell.
Linux allows you to change the default shell using the chsh command. The best way to change the default shell for your own logged in user is by specifying the shell name listed in the /etc/shells file with the -s option.
You must log out of the system so that the changes take into effect otherwise you’ll think that running chsh didn’t change the shell.
Did you notice that I had to specify the full path as it was listed in the /etc/shells file? If I had used chsh -s fish, it would have given me an error like “chsh: fish is an invalid shell”.
Which shell do you like?
Now that you know how to change shell, you may also read how to change users in Linux.
I hope this little article helped you to change the shell in Linux. If you have thought about changing the default shell, perhaps you use something other than the bash shell. Which shell is it? Why do you prefer it over the others?
Источник
How To Change The Default Shell In Linux
This article explains how to change the default shell in Linux. Using this you can set Bash, sh, Zsh, Csh, Fish, etc. as your shell.
The article includes instructions for changing the login shell from the command line using chsh, or changing the shell only for a particular terminal application. While the article is targeted at Linux users, this should also work on other Unix-like systems.
How to change the default login shell using chsh (from the command line)
To change the default login shell we’ll use chsh , a command line tool to change the login shell.
This program changes the login shell by modifying the /etc/passwd file and setting the $SHELL environment variable. You can override the default shell in a terminal application, by setting the shell from the terminal settings — see the second part of this article for details.
A note for Fedora users. Fedora doesn’t have chsh installed by default and to use it, you must install a package called util-linux-user . If you want to skip installing this package, you can use lchsh instead to change the login shell, which is available by default:
It’s important to note that using chsh, a normal user may only change the login shell for the current account, while the superuser may change the login shell for any account, including the root account. Also, the default behavior for non-root users is to accept only shells listed in the /etc/shells file, and issue a warning for root user.
So before changing your shell, list all the shells listed in the /etc/shells file from your Linux system by using the following command:
Example with output:
If the shell you want to use is not listed here, it may not be installed on your system. So install it (for example, install Zsh on Debian / Ubuntu / Linux Mint / Pop!_OS using: sudo apt install zsh ) and check again.
To change the shell for your user, run:
This runs chsh in an interactive mode, asking you for the password, then listing your current shell (most Linux distributions use Bash as the default shell) and asking you to enter a value for your new shell. Here’s the command with its output:
To change your shell, type the path to the new shell (which exists in /etc/shells ) and press the Enter key.
For example, to change the shell for the current user from Bash to Zsh:
In case you’re using a chsh version that doesn’t launch with an interactive prompt after executing chsh , change the login shell for your user directly:
E.g. to change the shell to Zsh:
After changing your account’s shell, logout and re-login to use the new shell.
To change the login shell for another user or for the root user, login to the shell prompt as root using su — , sudo -i , sudo su , etc., and run:
- To change the shell for the root account (and when prompted, enter the login shell you want to use, with its full path):
- To change the shell of another user (this also works for the root user, using root as the username):
This time we’ve used chsh with the -s option, which changes the login shell directly (doesn’t run in an interactive mode). Here, SHELL is the new shell (e.g. /bin/zsh ) and USERNAME is the user for which you’re changing the shell; for example, to change the shell to /bin/zsh for the user Logix , you’d use: chsh -s /bin/zsh Logix ).
Change the shell for your user in a terminal application
You can use a shell that’s different from the login shell ( $SHELL ) for a particular terminal application, if that application allows setting a custom shell or running a custom command instead of the default shell.
As a side note, you may also change the current shell (non-permanent change) by typing the shell command you want to use in a terminal (e.g. if you type «zsh», you’ll switch to using Zsh for that session; exit by typing «exit».).
Take GNOME Terminal for example (used in GNOME and Cinnamon desktops as the default terminal). Open its Preferences , click on the current active profile (usually called Default or Unnamed if you haven’t changed it or added new profiles) in the left-hand sidebar, then click on the Command tab:
This is where you can set a custom shell to be used with this application only. Enable the Run a custom command instead of my shell option, then in the Custom command field enter the full path to the shell you want to use, e.g. /bin/zsh , /bin/bash , etc.
In Xfce4 Terminal, open the Preferences and on the General tab you’ll need to enable an option called Run a custom command instead of my shell , then enter the custom command below that (this being the shell you want to use with this terminal, e.g. /bin/zsh , /usr/bin/fish , etc.).
Using KDE Plasma’s Konsole, go to Settings -> Edit Current Profile , and on the General tab, change the Command field to the full path of the shell you want to use (once again, something like: /bin/zsh , /bin/bash , /usr/bin/fish , etc.).
Using Guake, you can change the user shell from its Preferences , on the Shell tab, where you’ll find an option called Default interpreter that allows choosing any shell listed in /etc/shells .
For terminals that allow running a custom shell you should also find an option that allows running the command as a login shell (usually called just that: «Run command as a login shell»). To read on the differences between a login shell and an interactive shell, see this page.
Setting this is the same in most cases, so I won’t give any more examples. However, it’s worth noting that not all terminal applications have options to allow using a custom shell — in such cases, use the chsh command to change the login shell, as explained above.
Источник