Ubuntu 17.10 Gnome | Logout of current user and Login into another user using bash script

Asked by BoQsc

I'm writing a script and i'm required to completely log out of current user and login into another user, how can this be achieved?
Concidering that SU command is only switching user for bash shell console/terminal, and I actually need to switch completely to another user. That's why SU command is not what is needed for me.

I need the kind of command that kind of directly trigger "Switch User " button that can be seen in the GUI of Ubuntu's Gnome .

Example of loging-out command can be found here:
http://manpages.ubuntu.com/manpages/xenial/man1/gnome-session-quit.1.html

I need a login command similar to the above. Where I can type password and switch/login to that user.

Question information

Language:
English Edit question
Status:
Answered
For:
Ubuntu Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
actionparsnip (andrew-woodhead666) said :
#1

Why would you want to? What are you trying to achieve?

Linux is a true multiuser system so you can simply run a command as another user and it's profile and settings will be used. You can do this with su

su foo -c "gedit"

Will run gedit as the user foo

Revision history for this message
actionparsnip (andrew-woodhead666) said :
#2

su is not just for switching user in the shell. I suggest you read the su man pages

Revision history for this message
BoQsc (boqsc) said :
#3

Could you provide a quick example of SU usage that could be mainly related to solving my problem.
I looked at the man page http://man7.org/linux/man-pages/man1/su.1.html
And couldn't find anything useful, if you can, please direct me to the right parts or be more verbose.

Revision history for this message
BoQsc (boqsc) said :
#4

Well, mkusb creates an user after installation of the Ubuntu version. I want that after first boot up, when ubuntu automatiaclly logs into that user would create new fresh user, would log into it and remove mkboot created one. Without me having to do anything.

Revision history for this message
actionparsnip (andrew-woodhead666) said :
#5

Then add a script that runs as root at boot. It can manipulate the users as you want then reboot the server. You can remaster the OS to do this if you want. It's very flexible.

Revision history for this message
BoQsc (boqsc) said :
#6

It is a requirement for this to be done in a single boot, either after boot or before boot. Without a restart/reboot.

Revision history for this message
BoQsc (boqsc) said :
#7

Remastering OS would be closer to the solution, however the other way is also fascinating and might be needed in the near future.

Revision history for this message
BoQsc (boqsc) said :
#8

The one that is fascinated is: relogin/login into another user while in an user.

Revision history for this message
BoQsc (boqsc) said :
#9

I'm here not for a quickfix, temporary fix. I need a solution.

Revision history for this message
BoQsc (boqsc) said :
#10

A solution that I need to use in my bash script, the original problem.

Revision history for this message
Manfred Hampl (m-hampl) said :
#11

"Well, mkusb creates an user after installation of the Ubuntu version. I want that after first boot up, when ubuntu automatiaclly logs into that user would create new fresh user, would log into it and remove mkboot created one. Without me having to do anything."

1. I assume you wanted to mention mkusr and not mkusb
2. Why can't you create that new user at install time?
3. How does your script know what name the new user should get?
4. Should the new user have a password or not?

Revision history for this message
BoQsc (boqsc) said :
#12

1. You have to assume as it is, it is not an error:
The mkusb tool was developed to make it simpler and safer to create boot drives with the method to flash or clone an iso image or a compressed image file.
Now, i'm not sure if mkusb is using mkusr to create/modify user at the boot/preboot. It requires deeper knowledge of how mkusb works.

2. Why can't you create that new user at install time?
mkusb not really giving such option as far as I know,
also, I need "relogin", just to be sure in the future that I can easily automate that if in need at any work I might work.

3. How does your script know what name the new user should get?
It has no relations to the system so far, by now it is the default name I saw when original install of Ubuntu is completel.
So basicly the name is given by me - manualy according to what I saw after original Ubuntu instalation.

4. Should the new user have a password or not?
It should not have a password as, operating system installed via mkboot is mainly used in an USB device for a quick access to operating system.

Revision history for this message
Manfred Hampl (m-hampl) said :
#13

Please explain what exactly you want to achieve.

Are you taking about a single system, or should this be a preparation for a mass rollout on several similar systems?
Should the Ubuntu system be installed on the hard disk, or do you intend to boot a system from an external device (e.g. USB stick) without writing to the hard disk?

Revision history for this message
BoQsc (boqsc) said :
#14

Do you intend to boot a system from an external device (e.g. USB stick) without writing to the hard disk?
That's correct.

Are you taking about a single system, or should this be a preparation for a mass rollout on several similar systems?
Single system.

This "relogin" function that could be used in bash shell, that's all I want to achieve. What I have to do, what I have to learn and where is the documentation.

That would be good as a first start.

Revision history for this message
BoQsc (boqsc) said :
#15

 What I have to do, what I have to learn and where is the documentation and some tutorials on getting to that kind of level of modification of ubuntu-gnome.

Or is the Ubuntu in a bad state of providing quick clear straightforward hints about it's system modification, to the beginners?

Revision history for this message
Manfred Hampl (m-hampl) said :
#16

I think your approach is far too complicated.
Why do you want to boot a system with the "wrong" user, log that user out and do a new login of another user?
Why this additional step?

You have to be aware that if you start a script in the environment of one user, and this script logs that user out, all processes of that user will be stopped, including the script itself.

Revision history for this message
BoQsc (boqsc) said :
#17

"You have to be aware that if you start a script in the environment of one user, and this script logs that user out, all processes of that user will be stopped, including the script itself."

Well with root privilegies it is possible to send script file and continue it (If only Ubuntu has a "on user startup folder" like in Windows systems ). If it is true that without root access and only having the user's password it is impossible send a file to another user, just like switching a user - mentioned earlier, then I might be wrong, as I still have little to no depth experience with linux/gnu systems. (but I want to learn about it more)

I have had expectations about Ubuntu, that it works similarly to Windows, as ideas are similar, the implementations might be far worse in linux/gnu systems, as expectations of what is possible in the GUI of Ubuntu can't be directly represented in a script.

"Why do you want to boot a system with the "wrong" user, log that user out and do a new login of another user?
Why this additional step?"
Well, to have a choice, what is the other way to say to an user if he wants a clean new account, and give him a choice?

If you can, please give me steps on how to complete such task in a non-complicated way.

Revision history for this message
Manfred Hampl (m-hampl) said :
#18

Please explain:

Could it be possible to work with the "guest account" functionality of Ubuntu?
Should each user have his own username?
Are the users expected to store data on the USB device for access when they start the system the next time?

I am still missing the "big picture", how all the details mentioned previously should fit together.

Revision history for this message
A. Denton (aquina) said :
#19

From a system engineer standpoint of view this thread is leading nowhere. BoQsc your question is appreciated, but you haven't provided a satisfying answer with regards to what you actually want to accomplish.

On one instance you wrote "Remastering OS would be closer to the solution, however the other way is also fascinating and might be needed in the near future." which raises even more questions.

BoQsc, I'm sorry to say that but you're using up resources here on Launchpad to (probably) solve an architectural problem you just created, likely in an attempt to remaster Ubuntu or try out some weird deployment strategy.

Therefore you are advised to employ some regarded deployment and/or software management system like Remastersys, FAI, MAAS+Juju/OS etc., and manage that with Puppet, Ansible+Tower or the like.

Can you help with this problem?

Provide an answer of your own, or ask BoQsc for more information if necessary.

To post a message you must log in.