在Mac上制作操作系统安装U盘

想要在一台机器上安装Linux,并且打算用U盘作为安装介质,于是开始在Mac上制作安装U盘安装盘。

Step 1

准备好所需资源:

  1. Linux光盘镜像文件
  2. U盘一个,容量应大于等于Linux光盘镜像文件的大小

Step 2

将U盘插入到Mac,此时Mac应该自动识别到U盘,并能够在Finder中的设备列表中看到U盘。
在Terminal中输入diskutil list命令查看已经挂载的U盘:

1
2
3
4
5
6
7
8
9
10
11
$ diskutil list
/dev/disk0
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme *500.3 GB disk0
1: EFI EFI 209.7 MB disk0s1
2: Apple_HFS Macintosh HD 499.4 GB disk0s2
3: Apple_Boot Recovery HD 650.0 MB disk0s3
/dev/disk1
#: TYPE NAME SIZE IDENTIFIER
0: FDisk_partition_scheme *16.0 GB disk1
1: DOS_FAT_32 USB FLASH 16.0 GB disk1s1

可以看到U盘挂载到到了 /dev/disk1 ,不同情况下目标U盘挂载点可能有所不同,请注意识别,避免误操作其他的存储设备。

Step 3

接下来的操作需要U盘在非挂载的状态,所以我们来unmount这个U盘,这里用到的命令是diskutil unmountDisk:

1
$ sudo diskutil unmountDisk /dev/disk1

执行该命令后就无法在Finder中再看到该U盘了,但是通过diskutil list命令仍然能够看到。
关于 diskutil 的基本用法和参数,可以直接在终端输入diskutil命令并回车查看。

Step 4

现在可以开始向U盘写入已经准备好的Linux安装光盘镜像了,该操作需要用到dd命令:

1
$ sudo dd bs=4m if=~/Downloads/iso/debian-7.6.0-amd64-DVD-1.iso of=/dev/disk1

bs 用来指定输入和输出的块大小,我这里指定的是4兆字节, if 用来指定输入的源文件, of 用来指定输出的目标文件。如果iso文件较大,这个写入可能需要比较长的时间,在此过程中不会输出任何进度指示,需要耐心等待。

写入完成后,会打印类似下面的信息

1
2
3
939+1 records in
939+1 records out
3938795520 bytes transferred in 4847.252994 secs (812583 bytes/sec)

Done

现在已经完成了安装盘的制作,之后用这个U盘就可以在目的机器上安装写入的操作系统了。
补充一下,此方法适用与各种操作系统的安装。

阅读全文

在Mac下做文件转码

经常遇到从别人那里拿来的 Windows 下编辑的文本在 Mac 上打开全是乱码的问题,这时就需要对文件编码做一下转换才能正常阅读。

在 OS X 中可以用 iconv 命令来实现对文件转码:

1
iconv -f GB18030 -t UTF8 target.txt

批量转换如下:

1
2
cd target_files_dir
find *.txt -exec sh -c "iconv -f GB18030 -t UTF8 {} > {}.txt" \;

Permission denied when pushing to Github

现象

添加 remote 后,通过 git 协议 push 代码

1
2
$ git remote add origin git@github.com:angryz/icloudaegis_ejbca.git
$ git push -u origin master

此时出现错误提示

1
2
3
4
5
6
Warning: Permanently added the RSA host key for IP address '192.30.252.131' to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

处理

调试 ssh 连接

1
$ ssh -vT git@github.com

查看结果,连接正常,仍然报错 Permission denied (publickey).

检查 ssh 校验key是否是正常的

1
2
$ ssh-add -l
The agent has no identities.

没有打印出 key 信息,说明 ssh 连接时没有正确使用 key。

查看自己的 key 文件

1
$ ls ~/.ssh

在该目录下发现 github_rsa,接下来将其添加到 ssh

1
$ ssh-add ~/.ssh/github_rsa

然后再运行 ssh -vT git@github.com,正常。

总结

通常系统使用 ssh 协议时默认使用的 key 文件是 ~/.ssh/id_rsa,如果你针对某些 ssh 连接的 key 文件没有覆盖系统默认的 id_rsa,而是保存为自定义的文件名,那么就需要手动通过 ssh-add 将其添加到 ssh 协议的查找对象中。

参考 Github help: Error: Permission denied (publickey)

sudo执行命令时提示"command not found"

场景

当前用户是一个 sudoer,用 sudo 执行了一个命令,比如:sudo java -version,系统提示”command not found”。

原因

系统安装的 sudo 在编译时缺省使用了 —with-secure-path 参数,导致当前用户的 $PATH 环境变量在 sudo 时被覆盖掉了。

解决

方法一:简单的临时解决办法

编辑 ~/.bashrc,添加下面这行:

1
alias sudo="sudo env PATH=$PATH"

这个办法是在执行 sudo 时套用上当前的 $PATH 的值来达到目的。

方法二:另一个临时解决办法

编辑 etc/sudoers,添加下面这行:

1
Defaults secure_path="/bin:/usr/bin:/usr/local/bin:…"

方法三:根本解决办法

重新编译安装 sudo,不带 -–with-secure-path 参数。

在 CentOS5.3 上安装 Tomcat6 记录

为 Tomcat 创建专门的用户

考虑到安全问题,不建议用 root 用户运行 Tomcat,所以我们为 Tomcat 创建一个独立用户,

1
2
$ sudo useradd -d /usr/local/tomcat6 -s /sbin/nologin
$ sudo chown -R tomcat:tomcat /usr/local/tomcat6

安装和配置 JDK1.6

从 Oracle 下载 jdk-6u45-linux-x64.bin,拷贝到 /usr/local/jdk 下,

1
2
$ sudo chmod +x jdk-6u45-linux-x64.bin
$ sudo ./jdk-6u45-linux-x64.bin

会生成路径 /usr/local/jdk/jdk1.6.0_45,jdk文件都在其中。

安装和配置 Tomcat6

从 Apache 下载 apache-tomcat-6.0.37.tar.gz,

1
2
3
4
$ sudo tar zxvf apache-tomcat-6.0.37.tar.gz
$ sudo cp apache-tomcat-6.0.37/* /usr/local/tomcat6
$ sudo cd /usr/local/tomcat6
$ sudo chown -R tomcat:tomcat .

编辑环境变量

1
2
$ sudo vim /etc/profile

export PATH USER ... 上方添加以下变量声明,

1
2
3
4
5
JAVA_HOME=/usr/local/jdk/jdk1.6.0_45
JRE_HOME=/usr/local/jdk/jdk1.6.0_45/jre
CLASS_PATH=.:$JAVA_HOME/lib
CATALINA_HOME=/usr/local/tomcat6
CATALINA_BASE=$CATALINA_HOME

并在 export 后面追加新的内容,如下,

1
2
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL JAVA_HOME CATALINA_HOME
export PATH=$PATH:/usr/local/bin:$JAVA_HOME/bin

使环境变量生效,

1
$ source /etc/profile

阅读全文

配置Redmine通过smtp服务发送邮件通知

In order to deliver emails to users of Redmine, we need to complete the email configuration.

Email configuration of Redmine is contained in the configuration.yml file.

1
vim /var/www/redmine/config/configuration.yml

Let’s see a example email configuration first.

1
2
3
4
5
6
7
8
9
10
production:
email_delivery:
delivery_method: :smtp
smtp_settings:
address: smtp.mailserver.com
port: 25
domain: mailserver.com
authentication: :login
user_name: 'redmine@mydomain.com'
password: 'mypassword'

Because Redmine is developed with Ruby on Rails, so it’s email configuration is based on Action Mailer Configuration of Ruby on Rails.

delivery_method
The mail transport method to be used.
Valid settings:

  • :smtp
  • :sendmail
  • :async_smtp
  • :async_sendmail

The :async_smtp and :async_sendmail use asynchronous sends, which means Redmine does not wait for the email to be sent to display the next page. See Asynchronous Email Delivery for more details. Some SMTP servers have delay period before processing takes place as anti-spam feature, during which time synchronous method will block Redmine (10 seconds could be default value).

address
The SMTP server address to be used.

port
The SMTP server port to be used.

domain
You can specify your HELO domain in this setting.

authentication
The type of authentication method expected by your service provider.
Valid settings:

  • nil (or omit the key) for no authentication
  • :plain
  • :login
  • :cram_md5
    (note: if you set this to nil or omit it, you must not include the user_name and password settings)

user_name
If your mail server requires authentication, set the username in this setting.

password
If your mail server requires authentication, set the password in this setting.

And if you are using a TLS-requiring mail server, you’ll have to add this setting:
enable_starttls_auto
Valid Settings:

  • true
  • false
    Set this to true if you are using a TLS-requiring mail server.

Take GMail for example:

1
2
3
4
5
6
7
8
9
10
11
production:
email_delivery:
delivery_method: :smtp
smtp_settings:
enable_starttls_auto: true
address: smtp.gmail.com
port: 587
domain: smtp.gmail.com
authentication: :plain
user_name: 'my_google_id@gmail.com'
password: 'mypassword'

More examples

No Authentication

1
2
3
4
5
6
7
production:
email_delivery:
delivery_method: :smtp
smtp_settings:
address: smtp.mailserver.com
port: 25
domain: mydomain.com

Using sendmail command

For unix system command: /usr/sbin/sendmail

1
2
3
production:
email_delivery:
delivery_method: :sendmail

使用scp命令在linux主机之间复制文件/文件夹

在linux主机之间复制文件或文件夹是一个经常会遇到的操作,通常可以用ftp或sftp命令来传输文件,但是如果要传输文件夹,或者在两台remote主机之间传输文件,这两个命令就显得不够给力了。

scp是一个专门用来在linux主机之间传输文件的命令,它是基于ssh协议进行数据传输的,而且他可以直接传输文件夹,并且除了可以进行local和remote主机之间的文件之外,还可以实现两台remote主机之间的文件传输。

scp 命令的基本使用格式

1
2
scp [-12346BCEpqrv] [-c cipher] [-F ssh_config] [-i identity_file] [-l limit] [-o ssh_option] [-P port]
[-S program] [[user@]host1:]file1 ... [[user@]host2:]file2

先不考虑前面的可选参数,常用的方式如下

1
scp [[user@]host1:]file1 [[user@]host2:]file2

这里的user就是主机上的用户名称,因为是用ssh协议连接主机,所以格式是user@host这种形式。

例如,要将本地的一个文件复制到remote主机上,命令使用方式如下:

1
scp /home/zhangsan/this-is-source-file.tar.gz zhangsan@192.168.1.110:/data/uploads/this-is-target-file.tar.gz

阅读全文