Заметки сисадмина » information, mail user, su

Заметки сисадмина о интересных вещах из мира IT, инструкции и рецензии. Настраиваем Компьютеры/Сервера/1С/SIP-телефонию в Москве

information, mail user, su

2007-03-08 · Posted in FreeBSD

FreeBSD > Display information about the system

FreeBSD comes with different utilities, which can be use to gathered the information as per your needs.

1) Determining the Hardware Type/platform:
# uname –m

2) Determining machine processor architecture:
# uname –p

3) Determining FreeBSD release level:
# uname –r
Generally, following command is use to get all info at a time:
# uname -mrs
FreeBSD 5.0-RELEASE i386

4) Determining CPU information such as speed, make etc
# dmesg | grep CPU
CPU: Pentium 4 (1716.41-MHz 686-class CPU)
acpi_cpu0: on acpi0
acpi_cpu: CPU throttling enabled, 8 steps from 100% to 12.5%

5) Determining real and available memory to FreeBSD:
# dmesg | grep memory
real memory = 201326592 (192 MB)
avail memory = 188555264 (179 MB)

OR

# sysctl -a | grep hw.*mem
# sysctl -a | grep mem


hw.physmem: 194985984
hw.usermem: 167641088
hw.cbb.start_memory: 2281701376

Note systcl has more info, just type to see rest of all info :)
# sysctl -a | less

6) Determining how long a system has been up
# uptime

7) Determining when a system was last rebooted or shutdown
# last -1 reboot
# last -1 shutdown

8) Determining swap file system usage
# swapinfo –k

9) Determining who is logged in and what they are doing
Following all commands can be use. users command displays the list of all logged in users only.
# w
# who
# users

10) Find out when user was last logged in
You can use last command as follows:
# last user-name

(a) To find out user vivek was last logged at what time use last as follows
# last vivek

FreeBSD > Init to reboot or shutdown system

FreeBSD init works different ways. In BSD style, it specifies the kernel security level as follows:
-1: Permanently insecure mode.
0: Insecure mode
1: Secure mode
2: Highly secure mode
3: Network secure mode

You can get current security level (FreeBSD runlevel) using sysctl command:
# sysctl –a | grep kern.securelevel

You can setup new security level in /etc/rc.conf file:
1) Open file in text editor
# vi /etc/rc.conf

2) Add or modify following:
kern_securelevel_enable=”YES” # kernel security level
kern_securelevel=”2″ # range: -1..3 as above

3) Save the changes. Exit and restart FreeBSD.

If init used from command line i.e as a user process, init will emulate AT&T System V UNIX behavior as follows:

0: Halt and turn the power off
1: Go to single-user mode
6: Reboot the machine
c: Block further logins
q: Rescan the /etc/ttys file

1) To halt and turn the power off type:
# init 0

2) You can also use normal halt or shutdown command to shutdown system.

FreeBSD > Sending a Message to Windows Workstation

You can use the utility smbclient (part of samba server) to send a message to windows system from FreeBSD (or even from Linux/Solaris/UNIX).

Genral syntax of to send a message is as follows:
smbclient –M <WINDOW-SYSTEM-NAME> <<EOF
Message
Message

When the message is complete, press Control-D.

1) To send a message “Meeting cancelled” to windows system called joyxp
$ smbclient –M joyxp <<EOF
Meeting cancelled
See you at coffee house in 2 hrs.
–Vivek
EOF

2) With –U you can specify the username.
$ smbclient -M myxp -U VIVEK <<EOF
Meeting cancelled
See you at coffee house in 2 hrs.
EOF

FreeBSD > Sending a Message by E-Mail

E-mail is a way of sending a message between users and administrators from command prompt for shell script. Use mail command as follows

mail -s “Subject” username-name or email-id
email message
email message

..
When the message is complete, press Control-D or type dot character and press return/enter key.

1) To send email to root user to notify printing problem
mail -s “printing problem” root@admin.test.com

Hi Admin

I am having problem with printing can you please check up what is wrong with it. It was working fine untile late evening after that it is not printing from my HP-UX workstation.

Thanks

Joy D.

FreeBSD >Sending a Message to All Users on a Remote UNIX/Linux/FreeBSD System

Traditionally we used rwall command to send a message to every user on a network. Rwall works over insecure network. Instead of that, we can use wall command over ssh as follows, which is more secure and works with almost all UNIX variant.

1) ssh with wall syntax is as follows, after EOF press enter/return key and type message. When the message is complete, type EOF:
$ ssh root@remote-system wall<<EOF
message1
message2


EOF

2) To display message “Kernel is upgraded on this server. System is schedule to reboot in 45-minute time. Please logout and save your work” to ever user on remote FreeBSD system pweb.test.com

$ ssh root@pweb.test.com wall <<EOF
Kernel is upgraded on this server $(hostname).
System is schedule to reboot in 45-minute time.
Please logout and save your work.
Current local data and time is $(date)
EOF

Please note it might prompt for password if ssh-keys not used. Once password supplied it will execute wall command on remote server pweb.test.com. In order to work this remote UNIX/BSD/Linux must have sshd (ssh server) running. Also, notice that we have executed hostname and date command using command substitution feature of shell. This tips also works with Linux and other UNIX like operating system.

FreeBSD >Sending a Message to All Users on a System

You can use the wall command to send a message to every user on a system. General syntax of wall command:
# wall
Message
Message


When the message is complete, press Control-D.

1) To display message “Disk failure system will be down for 30 minute” to all users use wall as follows:
# wall
Disk failure system will be down for 30 minute
–UNIX Admin

2) To display message “Web server under DOS attack, come to IDC # 3” to all WHEEL group member use wall command with –g option as follows:
# wall –g wheel
Web server under DOS attack, come to IDC # 3 to investigate matter further.

FreeBSD > Sending a Message to an Individual User

You can send a message to an individual FreeBSD user logged into system using the write command. Typically writing a short message to an Individual user is main usage.

1) Use write command as follows
$ write user-name
Your message
Your message

When the message is complete, press Control-D

2) Here is an example of a message:
$ write joy
Do not use IRC in C Lab session.

3) Following message will be displayed on joy’s terminal:
Message from root@fbsd.test.com on ttyp0 at 13:24 …
Do not use IRC in C Lab session.

FreeBSD > Displaying System-Specific Messages at Login

Each time a user logs in to a system, the message of the day in the file /etc/motd is displayed. Use /etc/motd to give users information specific to the system, which someone logging in would want to know. Make sure /etc/motd has read permission to others and write permission to root user only:

1) Login as root or become root user using su

2) Use text editor vi to edit /etc/motd
# vi /etc/motd

3) Edit and save the changes. Next time the user logs in she will be able to see changes.

FreeBSD > Becoming super user (su) or enabling su access to user

The superuser is a privileged user with unrestricted access to all files and commands. The superuser has the special UID (user ID) 0. You need to become super user (root) only when tasks need root permissions. Here is how to become super user:

1) At shell prompt type su and press enter key, when prompted for password supply root user password:
$ su
password:
#

2) To exit super user status type exit or press CTRL+D
# exit
$

Please note that if you get an error su: Sorry for normal user account. Then following workaround needed to get rid of this problem:
1) For security, reason FreeBSD only allows su to user if user is member of wheel group. Wheel group is a special group for administration purpose. Add your normal user to this group using pw command using following:
# pw user mod -G wheel

2) So to add user test to group wheel run command as follows:
# pw user mod test -G wheel
# groups test

test wheel

3) Now su will work for test user.

You can disable this behavior complete for all users (not recommended until and unless you trust ALL your users):
1) Open pam configuration file for su using text editor:
# vi /etc/pam.d/su

2) Look for following line and comment it out:
Line:
auth requisite pam_wheel.so no_warn auth_as_self noroot_ok exempt_if_empty
Replace with:
#auth requisite pam_wheel.so no_warn auth_as_self noroot_ok exempt_if_empty

3) Now all users can use su if then knew the root password.

Leave a Reply