Как сменить пользователя в ubuntu
Перейти к содержимому

Как сменить пользователя в ubuntu

  • автор:

Log out, power off or switch users

When you have finished using your computer, you can turn it off, suspend it (to save power), or leave it powered on and log out.

Log out or switch users

User menu

To let other users use your computer, you can either log out, or leave yourself logged in and just switch users. If you switch users, all of your applications will continue running, and everything will be where you left it when you log back in.

To Log Out or Switch User , click the system menu on the right side of the top bar, click the button, and select the correct option.

The Log Out and Switch User entries only appear in the menu if you have more than one user account on your system.

See Also

  • Add a new user account — Add new users so that other people can log in to the computer.

Lock the screen

If you’re leaving your computer for a short time, you should lock your screen to prevent other people from accessing your files or running applications. When you return, you will see the lock screen . Enter your password to log back in. If you don’t lock your screen, it will lock automatically after a certain amount of time.

To lock your screen, click the system menu on the right side of the top bar and click the button.

When your screen is locked, other users can log in to their own accounts by clicking Log in as another user at the bottom right of the login screen. You can switch back to your desktop when they are finished.

See Also

  • Automatically lock your screen — Prevent other people from using your desktop when you go away from your computer.
  • The screen locks itself too quickly — Change how long to wait before locking the screen in the Screen Lock settings.

Suspend

To save power, suspend your computer when you are not using it. If you use a laptop, the system, by default, suspends your computer automatically when you close the lid. This saves your state to your computer’s memory and powers off most of the computer’s functions. A very small amount of power is still used during suspend.

To suspend your computer manually, click the system menu on the right side of the top bar, click the button, and select Suspend .

See Also

  • Set up automatic suspend — Configure your computer to suspend automatically.
  • Use less power and improve battery life — Tips to reduce the power consumption of your computer.
  • What happens when I suspend my computer? — Suspend sends your computer to sleep so it uses less power.

Power off or restart

If you want to power off your computer entirely, or do a full restart, click the system menu on the right side of the top bar, click the button, and select either Restart… or Power Off… .

If there are other users logged in, you may not be allowed to power off or restart the computer because this will end their sessions. If you are an administrative user, you may be asked for your password to power off.

You may want to power off your computer if you wish to move it and do not have a battery, if your battery is low or does not hold charge well. A powered off computer also uses less energy than one which is suspended.

How to switch between users on one terminal?

I’d like to log in as a different user without logging out of the current one (on the same terminal). How do I do that?

10 Answers 10

How about using the su command?

If you want to log in as root, there’s no need to specify username:

Generally, you can use sudo to launch a new shell as the user you want; the -u flag lets you specify the username you want:

There are more circuitous ways if you don’t have sudo access, like ssh username@localhost, but sudo is probably simplest, provided that it’s installed and you have permission to use it.

/.Xauthority` file is: -rw——- . I made a copy and that let me run gedit as an experiment.

Generally you use sudo to launch a new shell as the user you want; the -u flag lets you specify the username you want:

There are more circuitous ways if you don’t have sudo access, like ssh username@localhost , but I think sudo is probably simplest if it’s installed and you have permission to use it

This command prints the current user. To change users, we will have to use this command (followed by the user’s password):

After entering the correct password, you will be logged in as the specified user (which you can check by rerunning whoami .

HalosGhost's user avatar

If you’re running Ubuntu, and if the user you want to login as doesn’t have a password set:

Enter your own password and you should be set. Of course, this requires that your user has rights to gain root privileges with sudo .

To switch the terminal session to a different user, where that user can’t exit back into the original user, use exec:

This will technically login the new user in a new term process, and close out the current one. That way when the user attempts exit or Ctrl-D, the terminal will close as though that user was the one who instantiated it, i.e., the user can’t exit back into the original user’s term. Kind of pointless, considering they can still just start a new terminal session and automatically be in the original user term login, but there it is.

EDIT: For what it’s worth, you can use linux vlock command in your

/.bashrc to lock terminal sessions by default, requiring the password of the term session user to unlock. This would somewhat prevent the aforementioned term restart under the original user context, given the term isn’t instantiated using the non-default

Как сменить пользователя Ubuntu

Операционная система Ubuntu рассчитана на то, чтобы её использовали от имени одного определенного пользователя. Менять пользователя в процессе работы приходится не так уж часто. Обычно вы вводите логин и пароль при входе в систему, а затем пользуетесь ею пока не придёт пора выключать компьютер.

Если надо выполнить какие-либо действия с административными привилегиями, то для этого есть sudo. Однако иногда надо сменить пользователя Ubuntu. В этой статье мы поговорим о том как сделать это в графическом интерфейсе и в терминале.

Как сменить пользователя в Ubuntu

Сначала кликните по значку выключения в правом верхнем углу экрана и выберите там пункт Завершить сеанс или Сменить пользователя:

Затем подтвердите завершение сеанса или смену:

Далее перед вами откроется обычное окно входа, где вы сможете выбрать пользователя из списка или ввести его логин в поле ввода. Затем вы снова окажетесь на рабочем столе Ubuntu.

Теперь давайте поговорим как выполняется смена пользователя в терминале. Для этого надо использовать команду su. Например, чтобы сменить пользователя на losst достаточно выполнить:

Утилита запросит пароль пользователя losst после чего откроет командную строку от его имени:

Если вы хотите, чтобы путь к домашней папке и все другие переменные окружения для пользователя обновились используйте опцию -l или —login. Вместо неё также можно просто добавить чёрточку «-«. Например:

Если выполнить утилиту без параметров, то вы войдете от имени пользователя root. Но поскольку пароль root не задан по умолчанию, то следует добавить перед ней sudo:

В таком случае иногда целесообразнее использовать опцию -i команды sudo:

В этой статье мы рассмотрели как поменять пользователя в Ubuntu, как видите, здесь всё очень просто. Если остались вопросы, спрашивайте в комментариях!

Обнаружили ошибку в тексте? Сообщите мне об этом. Выделите текст с ошибкой и нажмите Ctrl+Enter.

How to switch user in terminal

How does one do this. I tried: su sensu but nothing happens.

terdon on strike's user avatar

1 Answer 1

You should use su :

If you specify the login option (either — , or -l , or —login : all are synonyms), you will get an environment similar to if you directly logged in as that user. Otherwise you stay in the current environment (e.g. many env variables, the current directory, etc).

Example: (note the usernames and current working directories!)

PS: If you run su not as root, you will of course be prompted for the password of the user as who you want to log in.

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *