CentOS 6, Debian, Ubuntu, CentOS 7, FreeBSD, CoreOS, 进入单用户模式(重新设置root密码),单用户模式修改密码

CentOS 6, Debian, Ubuntu, CentOS 7, FreeBSD, CoreOS, 进入单用户模式(重新设置root密码),单用户模式修改密码
CentOS 6, Debian, Ubuntu, CentOS 7, FreeBSD, CoreOS, 进入单用户模式修改密码

To reset the root password of your server, you will need to boot into single user mode.要重置您的服务器的root密码,您将需要引导进入单用户模式。

Access the Manage section of your server in the customer portal and follow these steps. The option depends on the bootloader version on the machine:

CentOS 6 进入单用户模式修改密码

  1. Click [View Console] to access the console and click the send CTRL+ALT+DEL button on the top right. Alternatively, you can also click [RESTART] to restart the server.
  2. You will see a GRUB boot prompt telling you to press any key - you have only a few seconds to press a key to stop the automated booting process. (If you miss this prompt you will need to restart the VM again)
  3. At the GRUB prompt, type "a" to append to the boot command.
  4. Add the text "single" and press enter.
  5. System will boot and you will see the root prompt. Type "passwd" to change the root-password and then reboot again.

Debian, Ubuntu, CentOS 7 进入单用户模式修改密码

  1. Click [View Console] to access the console and click the send CTRL+ALT+DEL button on the top right. Alternatively, you can also click [RESTART] to restart the server.
  2. As soon as the boot process starts, press ESC to bring up the GRUB boot prompt. You may need to turn the system off from the control panel and then back on to reach the GRUB boot prompt.
  3. You will see a GRUB boot prompt - press "e" to edit the first boot option. (If you do not see the GRUB prompt, you may need to press any key to bring it up before the machine boots)
  4. Find the kernel line (starts with "linux /boot/") and add init="/bin/bash" at the end of the line
  5. Press CTRL-X or F10 to boot.
  6. System will boot and you will see the root prompt. Type "mount -rw -o remount /" and then "passwd" to change the root password and then reboot again.

FreeBSD 进入单用户模式修改密码

The boot menu has an option to boot into single-user mode. Press the key for single user mode (2). At the root prompt, type "passwd" to change the root password and then reboot again.

CoreOS 进入单用户模式修改密码

CoreOS by default uses SSH key authentication. On Vultr, a root user and password are created. If an SSH key is selected when creating the VPS, this SSH key can be used to login as user "core".

It is possible to reset the standard root login by executing "sudo passwd" as user "core". Login as "core" using the SSH key first.

If you lost your SSH key, then you can login as the "core" user by editing the grub loader. Follow these steps:

  1. Click [View Console] to access the console and click the send CTRL+ALT+DEL button on the top right. Alternatively, you can also click [RESTART] to restart the server.
  2. You will see a GRUB boot prompt - press "e" to edit the first boot option. (If you do not see the GRUB prompt, you may need to press any key to bring it up before the machine boots)
  3. At the end of the line that begins with "linux$" add " coreos.autologin=tty1" (no quotes).
  4. Press CTRL-X or F10 to boot. You will be logged in as "core" when the system boots.
  5. Remember to reboot your server after you have reset your login.

完成

多用户,多(种\个)密钥,SSH 密钥登录linux服务器

接上文 Linux服务器采用密钥认证登录
多用户,多(种\个)密钥,SSH 密钥登录linux服务器
多用户,多种密钥算法(rsa\dsa),SSH 私钥登录linux(Red Hat \ CentOS \ Fedora \ Debian \ Ubuntu) 服务器
multi-user, multi-key (rsa \ dsa), private key ssh login linux server (Red Hat \ CentOS \ Fedora \ Debian \ Ubuntu)
使用密钥验证登录
基于密钥的安全验证必须为用户自己创建一对密钥,但是一台服务器上不可能只有一个用户,算法和强度也不会只有一种。

1:用户,假如一台服务器上有有两个用户root和demo
root //提前生成了两对rsa算法密钥
#ssh-keygen -t rsa -b 2048
#ssh-keygen -t rsa -b 16384 //rsa 最大位数16384

demo //demo 先使用dsa算法密钥,然后在使用rsa算法密钥,然后放到一起authorized_keys
$ssh-keygen -t dsa -b 1024 //dsa 位数必须是1024

2:dsa算法密钥SSH登录
ssh-keygen -t dsa -b 1024 //DSA keys must be 1024 bits
Generating public/private dsa key pair.
Enter file in which to save the key (/home/demo/.ssh/id_dsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/demo/.ssh/id_dsa.
Your public key has been saved in /home/demo/.ssh/id_dsa.pub.
The key fingerprint is:

demo
$cat ~/.ssh/id_dsa.pub>>~/.ssh/authorized_keys
#chmod 700 .ssh
#chmod 600 ~/.ssh/authorized_keys //不然Xshell 会提示 所选的用户密钥未在远程主机上注册。请再试一次。
//or willnotice The selected user key is not registered in the remote host.Try again.

3:rsa算法密钥SSH登录
$ssh-keygen -t rsa -b 2048 //最大值16384
Generating public/private rsa key pair.
Enter file in which to save the key (/home/demo/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/demo/.ssh/id_rsa.
Your public key has been saved in /home/demo/.ssh/id_rsa.pub.

demo
$cat ~/.ssh/id_rsa.pub>>~/.ssh/authorized_keys
#chmod 700 .ssh
#chmod 600 ~/.ssh/authorized_keys //不然Xshell 会提示 所选的用户密钥未在远程主机上注册。请再试一次。
//or willnotice The selected user key is not registered in the remote host.Try again.

4:多个密钥,多种密钥SSH登录
多密钥,只需要把公钥追加到authorized_keys
cat ~/.ssh/id_rsa.pub>>~/.ssh/authorized_keys

其他相关信息
ecdsa Xshell PUTTY还不支持,密钥认证是针对每个用户的。

-t type
Specifies the type of key to create. The possible values are
“rsa1” for protocol version 1 and “dsa”, “ecdsa”, “ed25519”, or
“rsa” for protocol version 2.
-b bits
Specifies the number of bits in the key tocreate. For RSA keys, the minimum size is 768 bits and
the default is 2048 bits. Generally,2048 bits is considered sufficient. DSA keys must be exactly
1024 bits as specified by FIPS 186-2. ForECDSA keys, the -b flag determines the key length by
selecting from one of three elliptic curvesizes: 256, 384 or 521 bits. Attempting to use bit lengths
other than these three values for ECDSA keyswill fail. ED25519 keys have a fixedlength and the
-b flag will be ignored.

ssh-keygen -t rsa -b 2048 //ssh-keygen -t rsa -b 65536,key bits exceeds maximum 16384
Bits has bad value 65536 (too large)
ssh-keygen -t rsa -b 16384
id_rsa
id_rsa.pub

ssh-keygen -t dsa -b 1024 //DSA keys must be 1024 bits
id_dsa
id_dsa.pub

ssh-keygen -t ecdsa -b 521
id_ecdsa
id_ecdsa.pub

ECDSA(椭圆曲线签名算法)
RSA公钥加密算法
DSA

结束
rsa

dsa

CentOS 6.x下安装(RPM和编译)aria2

CentOS 6.x下安装(RPM和编译)aria2
aria2 是一款 Linux 下轻量级的多线程下载工具,支持Http/Https、Ftp、BitTorrent、Metalink协议。
官网地址:http://aria2.sourceforge.net ,首页有简略使用教程(Usage Examples)
repo 里没有 aria2 ,因此需要到 http://pkgs.repoforge.org/aria2/ 去下载 rpm 包安装即可。

CentOS 6.x 32 位下安装
wget -c http://pkgs.repoforge.org/aria2/aria2-1.16.4-1.el6.rf.i686.rpm
rpm -ivh aria2-1.16.4-1.el6.rf.i686.rpm

CentOS 6.x 64 位下安装
wget -c http://pkgs.repoforge.org/aria2/aria2-1.16.4-1.el6.rf.x86_64.rpm
rpm -ivh aria2-1.16.4-1.el6.rf.x86_64.rpm

在安装过程有可能会出现缺少 libnettle.so.4 的错误提示。
因此需要先到 http://pkgs.repoforge.org/nettle/ 去下载安装 nettle 即可。
CentOS 6.x 32 位下安装
wget -c http://pkgs.repoforge.org/nettle/nettle-2.2-1.el6.rf.i686.rpm
wget -c http://pkgs.repoforge.org/nettle/nettle-devel-2.2-1.el6.rf.i686.rpm
rpm -ivh nettle-2.2-1.el6.rf.i686.rpm
rpm -ivh nettle-devel-2.2-1.el6.rf.i686.rpm

CentOS 6.x 64 位下安装
wget -c http://pkgs.repoforge.org/nettle/nettle-2.2-1.el6.rf.x86_64.rpm
wget -c http://pkgs.repoforge.org/nettle/nettle-devel-2.2-1.el6.rf.x86_64.rpm
rpm -ivh nettle-2.2-1.el6.rf.x86_64.rpm
rpm -ivh nettle-devel-2.2-1.el6.rf.x86_64.rpm

编译安装aria2
wget http://iweb.dl.sourceforge.net/project/aria2/stable/aria2-1.19.0/aria2-1.19.0.tar.gz
tar zxvf aria2-1.19.0.tar.gz
cd aria2-1.19.0
./configure
make
make install

man aria2c //查看 aria2c manual

aria2c http://cachefly.cachefly.net/100mb.test && rm -f 100mb.test
aria2c -c http://a/f.iso ftp://b/f.iso //-c 选项可以断点续传文件
aria2c http://example.org/mylinux.torrent
aria2c 'BitTorrent Magnet URI' -d test/ //-d test/是指明下载文件保存在test目录
aria2c http://example.org/mylinux.metalink
aria2c -i uris.txt //Download URIs found in text file

完成

Red Hat Enterprise Linux7.x(RHEL7.x)更换CentOS YUM源

Red Hat Enterprise Linux7.x(RHEL7.x)更换CentOS YUM源
Red Hat Enterprise Linux7.x(RHEL7.x) change CentOS YUM repository
Red Hat Enterprise Linux 7.1.1503(RHEL 7.1.1503)更换CentOS YUM源
由于RHEL的yum在线更新是收费的,RedHat在没有订阅授权的情况下是不能通过yum下载任何软件的,想使用RHEL系统,还想用yum源来在线安装软件,就需要更换成CentOS YUM源。
#cat /etc/redhat-release //查看版本
Red Hat Enterprise Linux Server release 7.1 (Maipo)

1、删除RHEL原有的yum
rpm -aq|grep yum|xargs rpm -e --nodeps //删除RHEL原有的yum
sudo rpm -ivh http://mirrors.ustc.edu.cn/centos/7.1.1503/os/x86_64/Packages/wget-1.14-10.el7_0.1.x86_64.rpm //安装wget

2、安装CentOS的yum
下载
wget http://mirrors.ustc.edu.cn/centos/7.1.1503/os/x86_64/Packages/python-iniparse-0.4-9.el7.noarch.rpm
wget http://mirrors.ustc.edu.cn/centos/7.1.1503/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
wget http://mirrors.ustc.edu.cn/centos/7.1.1503/os/x86_64/Packages/yum-3.4.3-125.el7.centos.noarch.rpm
wget http://mirrors.ustc.edu.cn/centos/7.1.1503/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-29.el7.noarch.rpm
安装
rpm -ivh python-iniparse-0.4-9.el7.noarch.rpm
rpm -ivh yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
rpm -ivh yum-3.4.3-125.el7.centos.noarch.rpm yum-plugin-fastestmirror-1.1.31-29.el7.noarch.rpm

3、下载源文件(CentOS 7)
https://lug.ustc.edu.cn/wiki/mirrors/help/centos //下载页面,根据需要进行下载

4、编辑源文件 CentOS-Base.repo

$releasever 替换成相应的版本号
$basearch 替换成想要的系统位数
编辑源文件 CentOS-Base.repo
http://mirrors.ustc.edu.cn/centos/7.1.1503/ //$releasever替换为7.1.1503 $basearch替换为x86_64,建议国内用户使用
http://mirror.vtti.vt.edu/centos/7.1.1503/ //$releasever替换为7.1.1503 $basearch替换为x86_64,建议国外用户使用

5、导入GPG key
sudo rpm --import http://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-7 //导入GPG key
sudo rpm --import http://mirror.vtti.vt.edu/centos/RPM-GPG-KEY-CentOS-7 //导入GPG key

6、安装扩展源
yum -y install epel-release //安装 Extra Packages for Enterprise Linux (EPEL)
yum clean all //清除YUM缓存
yum makecache //创建YUM缓存
yum repolist all //列出全部repository列表

http://mirrorlist.centos.org/?release=7.1.1503&arch=x86_64&repo=os
发现最适合自己的源
完成

CentOS6.x\Red Hat\Fedora\Linux 安装Wine 1.7.48 桌面运行环境教程

Open Source Software for running Windows applications on other operating systems
Wine (“Wine Is Not an Emulator” 的首字母缩写)是一个能够在多种 POSIX-compliant 操作系统(诸如 Linux,Mac OSX 及 BSD 等)上运行 Windows 应用的兼容层。 Wine 不是像虚拟机或者模拟器一样模仿内部的 Windows 逻辑,而是將 Windows API 调用翻译成为动态的 POSIX 调用,免除了性能和其他一些行为的内存占用,让你能够干净地集合 Windows 应用到你的桌面。
CentOS6.x\Red Hat\Fedora\Linux 安装Wine 1.7.48 桌面运行环境教程
主要分为两种安装方式:
1:yum 安装
2:源码编译安装(32和64位系统分别安装)

事先安装图形界面GNOME

Red Hat / CentOS / Fedora yum 安装

#yum -y install epel-release
#yum clean all //清空YUM缓存
#yum makecache //生成YUM缓存
yum repolist //确认EPEL状态
#yum -y install wine //安装wine
#yum upgrade wine //升级wine

Red Hat / CentOS / Fedora 源码编译 安装
CwntOS 32位系统安装

#yum -y install wget gcc make vim screen bzip2-devel epel-release zlib-devel libxcb-devel
#yum groupinstall "Development tools" -y
#yum clean all //清空YUM缓存
#yum makecache //生成YUM缓存
#yum repolist //确认EPEL状态
#yum -y update
#reboot
#wget http://nchc.dl.sourceforge.net/project/wine/Source/wine-1.7.48.tar.bz2 //下载wine
#tar -jxvf wine-1.7.48.tar.bz2 //解压
#cd wine-1.7.48
#./configure

configure: error: X development files not found. Wine will be built
#yum -y install libX11-devel freetype-devel
#./configure //配置
#make //编译
#make install //安装
#wine xxx.exe //运行32位软件

CentOS 64位系统安装

#yum groupinstall "Development tools" -y
#yum -y install wget gcc make vim screen bzip2-devel epel-release zlib-devel libxcb-devel
#yum -y update
#reboot
#wget http://nchc.dl.sourceforge.net/project/wine/Source/wine-1.7.48.tar.bz2 //下载wine
#tar -jxvf wine-1.7.48.tar.bz2 //解压
#cd wine-1.7.48
#./configure

configure: error: Cannot build a 32-bit program, you need to install 32-bit development libraries.

#./configure --enable-win64 //配置
configure: Finished. Do 'make' to compile Wine.

configure: error: X development files not found. Wine will be built

#yum -y install libX11-devel
#./configure --enable-win64

configure: error: FreeType development files not found. Fonts will not be built.
Use the --without-freetype option if you really want this.
#yum -y install freetype-devel
#./configure --enable-win64
configure: Finished. Do 'make' to compile Wine.
#make //编译
Wine build complete.
#make install //安装
#wine64 xxx.exe //运行64位软件
完成

linux的NetworkManager服务

linux (CentOS)配置IP地址信息,重启后网络配置失效。
经多次查找发现这种是NetworkManager的问题,NetworkManager试图将DHCP中获取的DNS信息写入/etc/resolv.conf,导致原文件被覆盖,
打开/etc/resolv.conf文件 会发现 Crate by networkmanager。

1:在配置文件添加 PEERDNS=no 这个选项可令/etc/resolv.conf 在系统重启后不会被重写,
重新启动后仍任被NetworkManager 重新创建了/etc/resolv.conf,该方法无效。

2:在文件属性中设置i参数避免文件被修改
#chattr +i /etc/resolv.conf

#chattr -i /etc/resolv.conf //如果你要修改此文件,移除i参数
重新启动后仍任被NetworkManager 重新创建了/etc/resolv.conf,该方法无效。

3:关闭该服务。
service NetworkManager stop 临时关闭:
chkconfig NetworkManager off 永久关闭:

关闭后正常

网络管理器最初由 Redhat 公司开发,现在由 GNOME 管理。

为CentOS 6.x安装图形界面GNOME

为CentOS 6.x安装图形界面GNOME、火狐浏览器并用TigerVNC 远程连接

为CentOS 6.6安装图形界面GNOME、火狐浏览器并用TigerVNC 远程连接
GNOME
易用性——设计和创建为所有人所用的桌面和应用程序
国际化——保证桌面和应用程序可以用于很多语言
火狐浏览器
Firefox 全球第三大流行的网页浏览器
VNC
VNC(Virtual Network Computing),为一种使用RFB协议的屏幕画面分享及远程操作软件


准备阶段:
#yum -y install wget gcc make vim screen epel-release
#yum clean all //清空YUM缓存
#yum makecache //生成YUM缓存
#yum repolist //确认EPEL状态
#yum -y update
#reboot

开始安装GNOME:
yum groupinstall "Development tools" -y
yum groupinstall "X Window System" "Desktop" "Chinese Support" "Fonts" -y

groupinstall "Desktop" #CentOS 6.x版本安装GNOME包
groupinstall "GNOME Desktop Environment" #CentOS 5.x版本安装GNOME包

开始安装配置TigerVNC Server:
yum -y install tigervnc-server

接下来设定VNC使用者进入后的环境,vim /etc/sysconfig/vncservers
下面是默认值,修改这里的用户和登入设定,他的值是 "索引号1:用户账号1 索引号2:用户账号2 索引号3:使用者账号3 ...."

索引值就是未来联机用的port号(5900+索引值),例如索引值2 (5900 + 2),所以到时连接 VNC Server 就使用 :5902
# VNCSERVERS="2:myusername"
# VNCSERVERARGS[2]="-geometry 800x600 -nolisten tcp -localhost"

多用户举例

VNCSERVERS="2:root 3:axer"
VNCSERVERARGS[2]="-geometry 1280x1024 -nolisten tcp -localhost"
VNCSERVERARGS[3]="-geometry 1280x1024"

单用户举例
VNCSERVERS="1:root"
VNCSERVERARGS[1]="-geometry 1360x768" //分辨率可以根据实际情况设置

用户必须是存在的

设定VNC的使用者密码
vnc的用户帐密和系统不同,需独立设定,使用指令 vncpasswd,切换到该用户下指令即可:

#vncpasswd
Password:
Verify:
你可能会忘记vnc的密码,只要把自己家目录中的 .vnc/passwd 档删掉然后重新执行 vncpasswd 即可。
#rm ~/.vnc/passwd

多用户务必设定后面中已指定的用户密码,否则在启动vnc会出现这样的错误:
3:axer
VNC password for user axer is not configured
[失败]
启动vnc/停止vnc
#service vncserver start | stop | restart

设定开机启动
#chkconfig --level 35 vncserver on

iptables防火墙
iptables -I INPUT -p tcp --dport 5901 -j ACCEPT
service iptables save
service iptables restart

其他

1. 如果启动时出现错误
正在启动 VNC 服务器:0:root A VNC server is already running as :0
这代表 /etc/sysconfig/vncservers 中有设定 "0"索引值,索引值得从1开始 VNCSERVERS="0:root 1:axer"

2. 查看正在开启的vnc server window
#vncserver -list

TigerVNC server sessions:

X DISPLAY # PROCESS ID
:1 6376
:2 6418

3. 强制关闭其中的显示,例如第2个
#vncserver -kill :2

vim /etc/inittab
id:3:initdefault //将3改为5,id:5:initdefault
系统启动,默认进入文字界面(默认为3);我们要让系统自动进入图形界面(数字5),所以把3改为5。

安装完毕后需要重新启动服务器

CentOS 7.x
#yum -y install wget gcc make vim screen epel-release
#yum clean all //清空YUM缓存
#yum makecache //生成YUM缓存
#yum repolist //确认EPEL状态
#yum -y update
#reboot

yum groupinstall "Development tools" -y
yum groupinstall "GNOME Desktop" -y

开始安装火狐浏览器:
yum -y install wget gcc make epel-release //更新yum源
yum -y install firefox //安装火狐浏览器

安装完毕后需要重新启动计算机或服务器

在CentOS6.x或CentOS7.x上安装EPEL Repo,Extra Packages for Enterprise Linux (EPEL)

CentOS6.x 安装升级Python2.7.x Python3.4.x

CentOS release 6.6 (Final) 安装升级Python2.7.7 Python2.7.9 Python3.4.3

1、查看当前系统中的python版本
#python --version 或 python -V
Python 2.6.6

2、检查CentOS版本
#cat /etc/redhat-release

3、安装所有的开发工具包
#yum groupinstall "Development tools" -y

4、安装其它的必需包
#yum install zlib-devel bzip2-devel openssl-devel ncurses-devel -y

5、下载、编译和安装Python2.7.7
cd /opt
wget https://www.python.org/ftp/python/2.7.7/Python-2.7.7.tgz
tar zxvf Python-2.7.7.tgz
cd Python-2.7.7
./configure
make install

5、下载、编译和安装Python3.4.3
cd /opt
wget https://www.python.org/ftp/python/3.4.3/Python-3.4.3.tgz
tar zxvf Python-3.4.3.tgz
cd Python-3.4.3
./configure
make install

6、查看Python版本。
用以下命令查看Python2.7是否已安装

#python2.7 --version
Python 2.7.7

用以下命令查看Python3.4是否已安装
#python3.4 --version
Python 3.4.3

7、更新系统默认Python和python-config版本(可选)
没必要的话最好不进行这项操作(可能会产生关联错误),建议使用python2 或者python3 代替。
先查找python的位置
#whereis python
python: /usr/bin/python2.6-config /usr/bin/python /usr/bin/python2.6 /usr/lib/python2.6 /usr/lib64/python2.6 /usr/local/bin/python3.4m
/usr/local/bin/python3.4-config /usr/local/bin/python3.4 /usr/local/bin/python3.4m-config /usr/local/lib/python3.4 /usr/include/python2.6
/usr/share/man/man1/python.1.gz

cd /usr/bin
rm python
rm python-config
ln -s /usr/local/bin/python3.4 /usr/bin/python //创建一个软连接
ln -s /usr/local/bin/python3.4m-config /usr/bin/python-config //创建一个软连接

#python --version
Python 3.4.3
reboot

8、安装和配置发行包(可选)
cd /opt
wget http://pypi.python.org/packages/source/d/distribute/distribute-0.6.27.tar.gz
tar xf distribute-0.6.27.tar.gz
cd distribute-0.6.27
python2.7 setup.py install

完成