一、ubuntu添加\删除\查看用户
1.添加用户有两种命令adduser和useradd
1.1 adduser yxf
创建新用户“yxf”,然后提示设置密码
创建完成之后在/home目录下会有“yxf”用户的家目录
1.2 useradd -m -s /bin/bash test
创建新用户“test”,再输入"passwd test"命令给“test”用户设置密码
创建完成之后在/home目录下会有“test”用户的家目录
useradd命令的各种参数使用见附件
2.删除用户
userdel -r yxf
删除“yxf”用户并将/home目录中的“yxf”用户家目录一并删除
3.查看所有用户
cat /etc/passwd
二、SSH安装与设置
1.安装
apt-get install openssh-server #服务端
apt-get install openssh-client #客户端
2.检查ssh服务是否启动
ps -e |grep ssh
看到sshd说明ssh-server已经启动了
3.启动ssh
/etc/init.d/ssh start
4.配置ssh
gedit /etc/ssh/sshd_config
在PermitRootLogin prohibit-password前加上#注释
在后边加上一句PermitRootLogin yes,然后保存
此设置是让root用户也可以通过ssh服务登入ubuntu
5.使用ssh服务登入
5.1 获取ubuntu服务器ip地址
ifconfig
5.2 命令登入test账号
ssh test@192.168.173.134
再输入test用户的密码
5.3 xshell软件登入
三、Samba安装与设置
1.安装
apt-get install samba
2.备份smb.conf文件
cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
3.配置samba
gedit /etc/samba/smb.conf
3.1 在此处增加:usershare owner only = False
3.2 找到[homes]项,此项默认是注释掉的,取消其注释,修改其具体内容,如下:
[homes]
comment = Home Directories
browseable = yes
# By default, the home directories are exported read-only. Change the
# next parameter to 'no' if you want to be able to write to them.
read only = no
# File creation mask is set to 0700 for security reasons. If you want to
# create files with group=rw permissions, set next parameter to 0775.
create mask = 0755 #建议将权限修改成0755,这样其它用户不能修改
# Directory creation mask is set to 0700 for security reasons. If you want to
# create dirs. with group=rw permissions, set next parameter to 0775.
directory mask = 0755
# By default, \\server\username shares can be connected to by anyone
# with access to the samba server. Un-comment the following parameter
# to make sure that only "username" can connect to \\server\username
# The following parameter makes sure that only "username" can connect
# This might need tweaking when using external authentication schemes
valid users = %S #本行需要取消注释,%s 是指登陆用户可以访问
此设置是让ubuntu用户所共享的目录为ubuntu用户对应的家目录
4.启动\重启\停止samba服务
/etc/init.d/smbd start #启动
/etc/init.d/smbd restart #重启
/etc/init.d/smbd stop #停止
5.增加samba帐号
smbpasswd -a 用户名(此用户名可以与ubuntu用户名一样,也可以不一样,建议一样)
然后提示输入密码(此密码可以与ubuntu对应用户名的密码一样,也可以不一样,建议一样)
6.查看所有账号
pdbedit -L
7.删除账号
smbpasswd -x 用户名
8.windows查看linux共享的文件夹
输入linux服务器的ip地址,然后再输入samba服务的账号和密码就可以在windows上看到linux所共享的文件夹
附件:
1.作用
useradd命令用来建立用户帐号和创建用户的起始目录,使用权限是超级用户。
2.格式
useradd [-d home] [-s shell] [-c comment] [-m [-k template]] [-f inactive] [-e expire ] [-p passwd] [-r] name
3.主要参数
-c:加上备注文字,备注文字保存在passwd的备注栏中。
-d:指定用户登入时的启始目录。
-D:变更预设值。
-e:指定账号的有效期限,缺省表示永久有效。
-f:指定在密码过期后多少天即关闭该账号。
-g:指定用户所属的群组。
-G:指定用户所属的附加群组。
-m:自动建立用户的登入目录。
-M:不要自动建立用户的登入目录。
-n:取消建立以用户名称为名的群组。
-r:建立系统账号。
-s:指定用户登入后所使用的shell。
-u:指定用户ID号。
4.说明
useradd可用来建立用户账号,它和adduser命令是相同的。账号建好之后,再用passwd设定账号的密码。使用useradd命令所建立的账号,实际上是保存在/etc/passwd文本文件中。
5.应用实例
在终端里执行以下命令:
# useradd -d /home/“username” -g “gid” -u “uid” -m -s /bin/bash “username”
# passwd “username”
“username"自己指定, ”gid"必须是现有的组id,“uid"必须目前未被使用
/etc/group文件里有所有组信息。以下命令可以创建新组:
# groupadd -g “gid” “group name”