We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x
Private

Adding New Users Access in the LInux OS

Medium Priority
164 Views
Last Modified: 2020-02-25
How do I create a user in Linux and grant them remote access via ssh ?

I am using the Redhat version of the Linux distribution.

I am new to Linux and is learning this OS as I go.

Alos any recommendations on how to master this OS would be appreciated.
Comment
Watch Question

Software Engineer
CERTIFIED EXPERT
Distinguished Expert 2019
Commented:

Adding a user:

useradd is the function to use: man useradd is where it is decribed.


On access through SSH:

It might need an extra group depending on settings in /etc/ssh/sshd_config

look for AllowGroup and/or AllowUser.


man sshd_config describes those options as well

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
You need to provide more detail.
Noci provided info on adding a new user.


The second part of your question depends on your setup. Whether you need to identify ip from where they will attempt to access.

/etc/hosts.allow whether you have rules for sshd:...
MURUGESAN NApplication Development and Automation Management
CERTIFIED EXPERT

Commented:
@Teavana
Sample code for playing using script
#!/bin/bash
#Doing unalias SETBINPATH since we are going to write a function SETBINPATH
#Ofcourse there is no alias SETBINPATH now. Due to enhancement/... in future we may add alias here.
#Hence performing unalias SETBINPATH
unalias SETBINPATH >/dev/null 2>&1
unset -f SETBINPATH
SETBINPATH ()
{
	if [ "-bash" = "$0" ]
	then
		echo "Inovking SETBINPATH in current shell not allowed"
	else
		if [ -f /usr/bin/ssh ]
		then
			SSH=/usr/bin/ssh
		elif [ -f /bin/ssh ]
		then
			SSH=/bin/ssh
		else
			echo "Update $0 using correct location of ssh"
			exit 1
		fi
		if [ -f /usr/bin/grep ]
		then
			EGREP='/usr/bin/grep -E'
		elif [ -f /bin/grep ]
		then
			EGREP='/bin/grep -E'
		elif [ -f /usr/bin/egrep ]
		then
			EGREP=/usr/bin/egrep
		elif [ -f /bin/egrep ]
		then
			EGREP=/bin/egrep
		else
			echo "Update $0 using correct location of grep or egrep"
			exit 1
		fi
		if [ -f /usr/bin/awk ]
		then
			AWK=/usr/bin/awk
		elif [ -f /bin/awk ]
		then
			AWK=/bin/awk
		else
			echo "Update $0 using correct location of awk"
			exit 1
		fi
		if [ -f /usr/sbin/adduser ]
		then
			ADDUSER=/usr/sbin/adduser
		elif [ -f /sbin/adduser ]
		then
			ADDUSER=/sbin/adduser
		else
			echo "Update $0 using correct location of adduser"
			exit 1
		fi
		if [ -f /usr/bin/getent ]
		then
			GETENT=/usr/bin/getent
		elif [ -f /bin/getent ]
		then
			GETENT=/bin/getent
		else
			echo "Update $0 using correct location of getent"
			exit 1
		fi
	fi
}
if [ "-bash" = "$0" ]
then
	echo "Executing 29172752.sh in current shell not allowed"
else
	if [ 0 -eq $# ]
	then
		echo "Usage:"
		echo "$0 NewUserName"
	else
		#Passing all parmeter passed to this script to the function SETBINPATH
		#Currently passing $@ not required. It might be required in future due to enhancement/modification/new requirements/...
		SETBINPATH $@
		NEWUSER="$@"
		$SSH root@REMOTEIP "AVAILABLEUSERS=\$($GETENT passwd |\
		$AWK -F: '{
			printf( \"%s \", \$1);
		}
		END {
			printf( \"\b\", \$1);
		}');
		for newuser in $NEWUSER;
		do
			echo \"\$AVAILABLEUSERS\" |\
			$EGREP -w \"\$newuser\" >/dev/null 2>&1;
			Ret=\$?;
			if [ 0 -eq \$Ret ];
			then
				echo \$newuser available at \$HOSTNAME;
			else
				echo \"$ADDUSER \$newuser -m -s /bin/bash -d /home/\$newuser\";
				$ADDUSER \"\$newuser\" -m -s /bin/bash -d \"/home/\$newuser\";
			fi;
		done;"
	fi
fi

Open in new window

MURUGESAN NApplication Development and Automation Management
CERTIFIED EXPERT

Commented:
>> any recommendations on how to master this OS would be appreciated
1. Install textpad.exe at personal system
I learned more during 2003 about regular expressions
if you prefer notepad++, use the same
2. install cygwin or vmplayer having linux always use man sed or man ... any command to know more about the options.
3. Look at available script files at Linux system.
Example:
$ /usr/bin/grep PROMPT_COMMAND= /etc/bashrc
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}";echo -ne "\007"'
$

Open in new window

Above command used to change the title of terminal
$ echo ${USER}
murugesandins
$ echo ${PWD/#$HOME/~}
/home/murugesandins
$ echo "${PWD/#$HOME/~}"
~
$ echo $PWD
/home/murugesandins
$ export PS1='$LOGNAME@$HOSTNAME $PWD [ $? ]
> $ '
murugesandins@murugesan /home/murugesandins [ 0 ]
$ /usr/bin/ls testing >/dev/null 2>&1
murugesandins@bmovm /home/murugesandins [ 2 ]
$ echo "2 being \$? since no such file or directory => testing"
2 being $? since no such file or directory => testing
murugesandins@bmovm /home/murugesandins [ 0 ]
$ #Comment prefixed using # previous $? being zero due to echo command.

Open in new window

A lot and lots available at bingo/google/www.experts-exchange.com
$ echo "bingo/google/www.experts-exchange.com" | /usr/bin/tr "/" "\n"
bingo
google
www.experts-exchange.com
$ echo "bingo/google/www.experts-exchange.com" | /usr/bin/tr "/" "\n" | /usr/bin/sort -u
bingo
google
www.experts-exchange.com
$ #Above command not written using search provider, but using /usr/bin/sort command

Open in new window

1)
https://www.iopb.res.in/unix-vi-editor.pdf
google/bingo:
file:pdf vi editor
sed (stream editor)
awk(alfred Aho, peter j Weinberger and brian Kernighan)
lsof
/etc/init.d/network
yum or rpm
nociSoftware Engineer
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:

@murugesandins

How do these answer the question asked?

1st post answer how to remotely add a user to a system , so an answer to a non-asked question. plain adduser is simpler... question is why to use what options, for that more info of the system is needed.

2nd post is a whole bunch a windows related stuff to learn how to access a system, this is about RH Linux, not sure how notepad++.exe or textpad.exe can help there.  Be free to try to run them on Linux..., it can be done.


While 

Q1) how to add a user

Q2) How to allow someone access to that account...

Are still not shown in your answers.

MURUGESAN NApplication Development and Automation Management
CERTIFIED EXPERT

Commented:
my last comment based on given query:
a)
>> any recommendations on how to master this OS would be appreciated
b)
>> Sample code for playing using script
providing related script to add user => Adding New Users Access in the LInux OS
If user has been already added, it will display related result.
else add that user at required system.

I have written the words "playing using script" to author => how to master this OS => to start playing from base version 0.9
nociSoftware Engineer
CERTIFIED EXPERT
Distinguished Expert 2019
Commented:

There is no windows mentioned .. so why advice on windows tools in a Linux question.

This is a better start if you need to begin with Linux:

https://www.experts-exchange.com/courses/2038/Certification-CompTIA-Linux.html

or:

https://www.tecmint.com/free-online-linux-learning-guide-for-beginners/

or:

https://cloudacademy.com/blog/linux-for-beginners-taking-your-first-steps/


As editor i would not suggest to start with vi  try nano first.



MURUGESAN NApplication Development and Automation Management
CERTIFIED EXPERT

Commented:
My preference started using vim from college days.
Faster and easier.
https://www.quora.com/Nano-is-easier-than-Vi-So-why-choose-Vi

Open in new window

Author

Commented:
Thank you all for your responses, I appreciate it.

Author

Commented:
Thank you all for your assistance.
MURUGESAN NApplication Development and Automation Management
CERTIFIED EXPERT

Commented:
most welcome.
nociSoftware Engineer
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
no problem. Goog luck with your journey.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.