How to detect the user has logged in a domain or local host in the linux shell script? The Next CEO of Stack OverflowGetting Linux computer integrated with Windows domainUnable to log in to Ubuntu server 10.04 after trying to join Windows domainAllow AD Groups to SUDOHow to remove unwanted Windows domain accounts and local account from Linux Mint 17 login screen?pssh (Parallel-ssh) passing different parameter for every hostHow to correctly set hostname and domain name?Can't create samba 4 share which accepts domain credentialsAfter joining with AD user, changing [User@domain@host] to [user@host]How to set sftp-server permissions and ownership in a shared sftp-folder? (ACL's ?)Debian Stretch: Samba Winbind Offline Logon Not working - kerberos keytab not persistent after reboot?

How to avoid supervisors with prejudiced views?

Make solar eclipses exceedingly rare, but still have new moons

Recycling old answers

Help understanding this unsettling image of Titan, Epimetheus, and Saturn's rings?

What connection does MS Office have to Netscape Navigator?

Solving system of ODEs with extra parameter

What flight has the highest ratio of time difference to flight time?

Would a grinding machine be a simple and workable propulsion system for an interplanetary spacecraft?

Prepend last line of stdin to entire stdin

Newlines in BSD sed vs gsed

Is there always a complete, orthogonal set of unitary matrices?

Why is quantifier elimination desirable for a given theory?

Is it ever safe to open a suspicious HTML file (e.g. email attachment)?

Why does the flight controls check come before arming the autobrake on the A320?

Why do remote US companies require working in the US?

Is it professional to write unrelated content in an almost-empty email?

How to install OpenCV on Raspbian Stretch?

Is micro rebar a better way to reinforce concrete than rebar?

Does soap repel water?

What steps are necessary to read a Modern SSD in Medieval Europe?

Why don't programming languages automatically manage the synchronous/asynchronous problem?

Why does standard notation not preserve intervals (visually)

How did people program for Consoles with multiple CPUs?

Method for adding error messages to a dictionary given a key



How to detect the user has logged in a domain or local host in the linux shell script?



The Next CEO of Stack OverflowGetting Linux computer integrated with Windows domainUnable to log in to Ubuntu server 10.04 after trying to join Windows domainAllow AD Groups to SUDOHow to remove unwanted Windows domain accounts and local account from Linux Mint 17 login screen?pssh (Parallel-ssh) passing different parameter for every hostHow to correctly set hostname and domain name?Can't create samba 4 share which accepts domain credentialsAfter joining with AD user, changing [User@domain@host] to [user@host]How to set sftp-server permissions and ownership in a shared sftp-folder? (ACL's ?)Debian Stretch: Samba Winbind Offline Logon Not working - kerberos keytab not persistent after reboot?










1















In the default, the linux doesn't support the domain. But the user can join a domain by applictions, such as: Likewise, Winbind, and so on.

For my project, my customers are all enterprise members. For the security problem, most customers' linux host will be joined a domain.

Unfortunately, the customer can log in the local host even the linux host has been joined a domain. Such as:

(1) The are two accounts in a linux host:

a domain account: dev.comjohn(the domain is developer.com)

a local account: tom

(2) The customer can log in with the domain account(dev.comjohn) or local account(tom) freely.



My task is that write a shell script that will be executed when the user log in. In the shell script, I need to check the user log in with a domain account or a local account.

If the user log in with the domain name, I need to get the domain name ; otherwise, I need to get the host name. Then report the domain(or host) name and user name to the remote monitor server.



I have tried the following code:



hostName=$(hostname) 
hostFQDN=$(hostname -f)

if [ "$hostName" = "$hostFQDN" ]; then
# The user didn't log in a domain.
hostInfo="$hostName"
else
# The user logged in a domain.
hostInfo=$(hostname -d)
fi


In the above, I check the host FQDN is equal with the host name or not. If yes, I will believe the customer log in with the domain account; else, local account.



Unfortunately, it doesn't work always. The reason is that the host FQDN will not equal with host name always if the linux host is joined a domain, even the customer log in with a local account. Such as:

(1) The linux host is joined the domain "dev.com";

(2) The host fqdn will be "yw-host.dev.com" always("yw-host" is the host name), whether the customer log in with domain account or not.



Anybody can give a solution please? As my customer can join the domain with multiple domain applications(such as: likewise, winbin, and so on), it is better the solution will not depend on a special domain application.



Thanks a lot.










share|improve this question






















  • I have an idea that check the user id is in the file etc/passwd or not. If yes, it should be a local account; else, a domain account. I am not sure this solution is correct or not.

    – yw5643
    May 13 '15 at 7:21












  • Anybody can give some comments? Thanks.

    – yw5643
    May 18 '15 at 2:50















1















In the default, the linux doesn't support the domain. But the user can join a domain by applictions, such as: Likewise, Winbind, and so on.

For my project, my customers are all enterprise members. For the security problem, most customers' linux host will be joined a domain.

Unfortunately, the customer can log in the local host even the linux host has been joined a domain. Such as:

(1) The are two accounts in a linux host:

a domain account: dev.comjohn(the domain is developer.com)

a local account: tom

(2) The customer can log in with the domain account(dev.comjohn) or local account(tom) freely.



My task is that write a shell script that will be executed when the user log in. In the shell script, I need to check the user log in with a domain account or a local account.

If the user log in with the domain name, I need to get the domain name ; otherwise, I need to get the host name. Then report the domain(or host) name and user name to the remote monitor server.



I have tried the following code:



hostName=$(hostname) 
hostFQDN=$(hostname -f)

if [ "$hostName" = "$hostFQDN" ]; then
# The user didn't log in a domain.
hostInfo="$hostName"
else
# The user logged in a domain.
hostInfo=$(hostname -d)
fi


In the above, I check the host FQDN is equal with the host name or not. If yes, I will believe the customer log in with the domain account; else, local account.



Unfortunately, it doesn't work always. The reason is that the host FQDN will not equal with host name always if the linux host is joined a domain, even the customer log in with a local account. Such as:

(1) The linux host is joined the domain "dev.com";

(2) The host fqdn will be "yw-host.dev.com" always("yw-host" is the host name), whether the customer log in with domain account or not.



Anybody can give a solution please? As my customer can join the domain with multiple domain applications(such as: likewise, winbin, and so on), it is better the solution will not depend on a special domain application.



Thanks a lot.










share|improve this question






















  • I have an idea that check the user id is in the file etc/passwd or not. If yes, it should be a local account; else, a domain account. I am not sure this solution is correct or not.

    – yw5643
    May 13 '15 at 7:21












  • Anybody can give some comments? Thanks.

    – yw5643
    May 18 '15 at 2:50













1












1








1








In the default, the linux doesn't support the domain. But the user can join a domain by applictions, such as: Likewise, Winbind, and so on.

For my project, my customers are all enterprise members. For the security problem, most customers' linux host will be joined a domain.

Unfortunately, the customer can log in the local host even the linux host has been joined a domain. Such as:

(1) The are two accounts in a linux host:

a domain account: dev.comjohn(the domain is developer.com)

a local account: tom

(2) The customer can log in with the domain account(dev.comjohn) or local account(tom) freely.



My task is that write a shell script that will be executed when the user log in. In the shell script, I need to check the user log in with a domain account or a local account.

If the user log in with the domain name, I need to get the domain name ; otherwise, I need to get the host name. Then report the domain(or host) name and user name to the remote monitor server.



I have tried the following code:



hostName=$(hostname) 
hostFQDN=$(hostname -f)

if [ "$hostName" = "$hostFQDN" ]; then
# The user didn't log in a domain.
hostInfo="$hostName"
else
# The user logged in a domain.
hostInfo=$(hostname -d)
fi


In the above, I check the host FQDN is equal with the host name or not. If yes, I will believe the customer log in with the domain account; else, local account.



Unfortunately, it doesn't work always. The reason is that the host FQDN will not equal with host name always if the linux host is joined a domain, even the customer log in with a local account. Such as:

(1) The linux host is joined the domain "dev.com";

(2) The host fqdn will be "yw-host.dev.com" always("yw-host" is the host name), whether the customer log in with domain account or not.



Anybody can give a solution please? As my customer can join the domain with multiple domain applications(such as: likewise, winbin, and so on), it is better the solution will not depend on a special domain application.



Thanks a lot.










share|improve this question














In the default, the linux doesn't support the domain. But the user can join a domain by applictions, such as: Likewise, Winbind, and so on.

For my project, my customers are all enterprise members. For the security problem, most customers' linux host will be joined a domain.

Unfortunately, the customer can log in the local host even the linux host has been joined a domain. Such as:

(1) The are two accounts in a linux host:

a domain account: dev.comjohn(the domain is developer.com)

a local account: tom

(2) The customer can log in with the domain account(dev.comjohn) or local account(tom) freely.



My task is that write a shell script that will be executed when the user log in. In the shell script, I need to check the user log in with a domain account or a local account.

If the user log in with the domain name, I need to get the domain name ; otherwise, I need to get the host name. Then report the domain(or host) name and user name to the remote monitor server.



I have tried the following code:



hostName=$(hostname) 
hostFQDN=$(hostname -f)

if [ "$hostName" = "$hostFQDN" ]; then
# The user didn't log in a domain.
hostInfo="$hostName"
else
# The user logged in a domain.
hostInfo=$(hostname -d)
fi


In the above, I check the host FQDN is equal with the host name or not. If yes, I will believe the customer log in with the domain account; else, local account.



Unfortunately, it doesn't work always. The reason is that the host FQDN will not equal with host name always if the linux host is joined a domain, even the customer log in with a local account. Such as:

(1) The linux host is joined the domain "dev.com";

(2) The host fqdn will be "yw-host.dev.com" always("yw-host" is the host name), whether the customer log in with domain account or not.



Anybody can give a solution please? As my customer can join the domain with multiple domain applications(such as: likewise, winbin, and so on), it is better the solution will not depend on a special domain application.



Thanks a lot.







linux shell-script domain






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked May 13 '15 at 7:20









yw5643yw5643

58211




58211












  • I have an idea that check the user id is in the file etc/passwd or not. If yes, it should be a local account; else, a domain account. I am not sure this solution is correct or not.

    – yw5643
    May 13 '15 at 7:21












  • Anybody can give some comments? Thanks.

    – yw5643
    May 18 '15 at 2:50

















  • I have an idea that check the user id is in the file etc/passwd or not. If yes, it should be a local account; else, a domain account. I am not sure this solution is correct or not.

    – yw5643
    May 13 '15 at 7:21












  • Anybody can give some comments? Thanks.

    – yw5643
    May 18 '15 at 2:50
















I have an idea that check the user id is in the file etc/passwd or not. If yes, it should be a local account; else, a domain account. I am not sure this solution is correct or not.

– yw5643
May 13 '15 at 7:21






I have an idea that check the user id is in the file etc/passwd or not. If yes, it should be a local account; else, a domain account. I am not sure this solution is correct or not.

– yw5643
May 13 '15 at 7:21














Anybody can give some comments? Thanks.

– yw5643
May 18 '15 at 2:50





Anybody can give some comments? Thanks.

– yw5643
May 18 '15 at 2:50










1 Answer
1






active

oldest

votes


















0














The full user login detail should be in your secure or audit log depending on which distro you are using.
It is a simple quick fix to check if they exist in /etc/passwd but you could have issues with duplicate usernames.






share|improve this answer








New contributor




Koffee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f203107%2fhow-to-detect-the-user-has-logged-in-a-domain-or-local-host-in-the-linux-shell-s%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    The full user login detail should be in your secure or audit log depending on which distro you are using.
    It is a simple quick fix to check if they exist in /etc/passwd but you could have issues with duplicate usernames.






    share|improve this answer








    New contributor




    Koffee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.
























      0














      The full user login detail should be in your secure or audit log depending on which distro you are using.
      It is a simple quick fix to check if they exist in /etc/passwd but you could have issues with duplicate usernames.






      share|improve this answer








      New contributor




      Koffee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















        0












        0








        0







        The full user login detail should be in your secure or audit log depending on which distro you are using.
        It is a simple quick fix to check if they exist in /etc/passwd but you could have issues with duplicate usernames.






        share|improve this answer








        New contributor




        Koffee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.










        The full user login detail should be in your secure or audit log depending on which distro you are using.
        It is a simple quick fix to check if they exist in /etc/passwd but you could have issues with duplicate usernames.







        share|improve this answer








        New contributor




        Koffee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        share|improve this answer



        share|improve this answer






        New contributor




        Koffee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        answered 2 days ago









        KoffeeKoffee

        13




        13




        New contributor




        Koffee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.





        New contributor





        Koffee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.






        Koffee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f203107%2fhow-to-detect-the-user-has-logged-in-a-domain-or-local-host-in-the-linux-shell-s%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            getting Checkpoint VPN SSL Network Extender working in the command lineHow to connect to CheckPoint VPN on Ubuntu 18.04LTS?Will the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayVPN SSL Network Extender in FirefoxLinux Checkpoint SNX tool configuration issuesCheck Point - Connect under Linux - snx + OTPSNX VPN Ububuntu 18.XXUsing Checkpoint VPN SSL Network Extender CLI with certificateVPN with network manager (nm-applet) is not workingWill the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayImport VPN config files to NetworkManager from command lineTrouble connecting to VPN using network-manager, while command line worksStart a VPN connection with PPTP protocol on command linestarting a docker service daemon breaks the vpn networkCan't connect to vpn with Network-managerVPN SSL Network Extender in FirefoxUsing Checkpoint VPN SSL Network Extender CLI with certificate

            Cannot Extend partition with GParted The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Community Moderator Election ResultsCan't increase partition size with GParted?GParted doesn't recognize the unallocated space after my current partitionWhat is the best way to add unallocated space located before to Ubuntu 12.04 partition with GParted live?I can't figure out how to extend my Arch home partition into free spaceGparted Linux Mint 18.1 issueTrying to extend but swap partition is showing as Unknown in Gparted, shows proper from fdiskRearrange partitions in gparted to extend a partitionUnable to extend partition even though unallocated space is next to it using GPartedAllocate free space to root partitiongparted: how to merge unallocated space with a partition

            Marilyn Monroe Ny fiainany manokana | Jereo koa | Meny fitetezanafanitarana azy.