Sponsored Content
Top Forums Shell Programming and Scripting problem with changing default home directory Post 302239386 by tjay83 on Tuesday 23rd of September 2008 01:47:25 PM
Old 09-23-2008
problem with changing default home directory

Hi
I want to change the default home directory of a user by modifying the /etc/passwd.

I have a user named John
cat /etc/passwd | grep John

john:x:503:506::/home/john/:/bin

Here is my script:

Code:
echo "Enter username";
read username;

echo "Enter new home directory";
read new_path;

awk -v user="$username" -v path="$new_path" 'BEGIN{FS=OFS=":"}$1==user{$6=$new_path}1' /etc/passwd > /etc/passwd.new && mv /etc/passwd.new /etc/passwd;;

I enter:
john
/home/tomas

cat /etc/passwd

john:x:503:506::john:x:503:506::/home/john:/bin/bash:/bin/bash

however it should be :

john:x:503:506::/home/tomas/:/bin

How can I correct it?
 

9 More Discussions You Might Find Interesting

1. Solaris

home directory problem

I have solaris 9 installed across 2 disks. disk 1 / s0 swap s1 /usr s6 /var s3 /home s7 disk2 /swapfile (spare space for use with swap) s1 /opt s5 /export/home s7 When I create a new user using solaris Management... (1 Reply)
Discussion started by: finster
1 Replies

2. UNIX for Dummies Questions & Answers

user home directory problem

The home directory for me on my system is on /home/kwon. It was created using "useradd kwon" When i go to change the home directory for a user doing a usermod -d /home/test when they log on it gives them messages saying to generate new ssh keys, and it does. It gives me a thing that says... (1 Reply)
Discussion started by: BangYourWallnut
1 Replies

3. UNIX for Dummies Questions & Answers

Can I prevent a user from changing the permissions on their home directory.

Hello All, I have a new HPUX system going into production and it will be used by 2 projects. One of the contract requirements is the 2 groups can not have access to the others work or data. I believe I have the system pretty well locked up using groups and permissions and selective mounting of... (2 Replies)
Discussion started by: DanL
2 Replies

4. Shell Programming and Scripting

Problem with changing directory and subdirectories to read only

I have a directory with its subdirectories and files. I want to change them all to read only. Say it is ~/test chmod -R 444 ~/test chmod: `/home/myname/test': permission denied I do not understand. Do I have to have executable mode for a diirectory to access. How can I change ~/test to... (5 Replies)
Discussion started by: lalelle
5 Replies

5. UNIX for Advanced & Expert Users

Problem: Automounting Home directory for nis & nfs configuration doesn't work

Hi all, First of all, i am so sorry about my bad level in English writing. I have some problem in linux and i hope the experts of this forum to help me if they have enough time to reply to me. I have a scenario of configuring NIS and NFS in Redhat Linux environment such that user can login... (0 Replies)
Discussion started by: pioneer
0 Replies

6. Shell Programming and Scripting

Changing home directory

Hello All: I have an LDAP server that is used for authentication. Now the home directory id set to : /export/home/user1 . But I am logging in to different machines Solaris, Linux. The problem is I want the home directory to change depending on the os version (e.g. /export/home/user1/linux). Can... (1 Reply)
Discussion started by: disturbe_d
1 Replies

7. HP-UX

Changing the default login directory of a user

I want to change the default login directory of a user from /home/user to a new directory. how can i do this? thanks in advance....:) (1 Reply)
Discussion started by: smahe23
1 Replies

8. Solaris

User's Home directory ownership is changing Automatically

Hi , on my Solaris 10 machine user's home directory ownership is being changed automatically to their UID. can any one please tell me whats the reason behind it . users are there in /etc/passwd file . /etc/shadow file is also there along with nssswitch.conf file and there is no changes made to... (5 Replies)
Discussion started by: usernew
5 Replies

9. Solaris

SunOS confusing root directory and user home directory

Hello, I've just started using a Solaris machine with SunOS 5.10. After the machine is turned on, I open a Console window and at the prompt, if I execute a pwd command, it tells me I'm at my home directory (someone configured "myuser" as default user after init). ... (2 Replies)
Discussion started by: egyassun
2 Replies
passwd(5yp)															       passwd(5yp)

Name
       passwd - password file description with the Yellow Pages service implemented

Description
       The  file  stores  initial login information, including passwords for each user in the system.  Regardless of whether or not the system has
       the Yellow Pages service implemented, the file contains the following information:

       Name (login name, contains no uppercase)
       Encrypted password
       Numerical user ID
       Numerical group ID
       User's real name, office, extension, home phone.
       Initial working directory
       Program to use as Shell

       The name can contain an ampersand (&), meaning insert the login name.  This information is set by the command and used by the command.

       This is an ASCII file.  Each field within each user's entry is separated from the next by a colon.  Each user is separated from the next by
       a new line.  If the password field is null, no password is demanded; if the shell field is null, the system defaults to the shell.

       This  file resides in the directory.  Because of the encrypted passwords, it can and does have general read permission and can be used, for
       example, to map numerical user IDs to names.

       Appropriate precautions must be taken to lock the file against simultaneous changes if it is to be edited with a text editor.  The  command
       does the necessary locking.

       In  a Yellow Pages environment, the file can also have a line beginning with a plus (+), which means to incorporate entries from the Yellow
       Pages data base.  There are three styles of + entries: by itself, + means to insert the entire contents of the Yellow Pages  password  file
       at  that  point;  +name means to insert the entry (if any) for name from the Yellow Pages at that point; +@name means to insert the entries
       for all members of the network group name at that point.  If a + entry has a nonnull password, directory, gecos, or shell  field,  it  will
       override what is contained in the Yellow Pages.	The numerical user ID and group ID fields cannot be overridden.

Examples
       Here is a sample file:
       root:q.mJzTnu8icF.:0:10:Privileged Account:/:/bin/csh
       jcj:6k/7KCFRPNVXg:508:10:JC Javert:/usr2/jcj:/bin/csh
       +john:
       +@documentation:no-login:
       +:::Guest

       In  this  example,  there  are  specific entries for users root and jcj, in case the Yellow Pages are temporarily out of service.  Alterna-
       tively, a user may need specific login information on a given system that differs from the information contained in the	Yellow	Pages  map
       for that user.  The user, john, will have his password entry in the Yellow Pages incorporated without change.  Anyone in the netgroup docu-
       mentation will have their password field disabled, and anyone else will be able to log in with their usual password, shell, and home direc-
       tory, but with a gecos field of Guest.

Files
See Also
       chfn(1), finger(1), login(1), passwd(1), crypt(3), getpwent(3), group(5), adduser(8), vipw(8)

																       passwd(5yp)
All times are GMT -4. The time now is 02:55 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy